tags:

views:

125

answers:

2

I am trying to develop a REST style application with Spring but the url mapping is not working as I expected.

in web.xml I have

 <servlet-mapping>
    <servlet-name>UrlParsing</servlet-name>
    <url-pattern>/device/</url-pattern>
 </servlet-mapping>

in NetTRaceHQ-servlet.xml I have

   <bean name="urlMapping" 
      class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="/**/device/**">devicesController</prop>
        </props>
   </property>
</bean>

I would like to use to map the following urls to the devicesController

http://localhost:8080/NetTraceHQ/admin/device/1  
http://localhost:8080/NetTraceHQ/admin/device/  
http://localhost:8080/NetTraceHQ/admin/device  enter code here

The current setting in NetTRaceHQ-servlet.xml works for
http://localhost:8080/NetTraceHQ/admin/device

but the others fail. I have tried

 /**/device/*  
 /**/device  
 /**/device/**/  
 /admin/device/*

and more with no luck

Googled for answers and have not had any luck.

A: 

That should work, I think, which makes me wonder if something else is mis-configured. The Spring component that handles this matching is org.springframework.util.AntPathMatcher, so have a read of that javadoc in case you've missed something.

Otherwise, try setting your handler as the defaultHandler in the url mapping, just to make sure that everything else is workign fine, so you can narrow down your problem to your path matching.

skaffman
A: 

Configure the resolver by setting alwaysUseFullPath to true.

< bean name="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> < property name="mappings"> < props> < prop key="//device/">devicesController< /prop> < /props> < /property> < property name="alwaysUseFullPath"> < value>true< /value> < /property>

< /bean>

-Varghees Samraj

Varghees Samraj