Reputation: 1175
I am running Spring MVC on JBoss app server.
File: jboss-web.xml :
<jboss-web>
<context-root>/foo/bar/baz</context-root>
</jboss-web>
Context root is defined as /foo/bar/baz something I can't change.
File: web.xml:
<servlet>
<servlet-name>spring-rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
It has the dispatcher servlet mapped to url "/"
Java: (Controller)
@RequestMapping(value="/rest/*", method = RequestMethod.POST)
@ResponseBody
public SomeResponse processRequest(@RequestBody SomeRequest someRequest)
{
return someResponse;
}
I am trying to process the request in this method.
When Spring gets loaded in JBoss, I see the following: [
DefaultAnnotationHandlerMapping] Mapped URL path [/rest/*] onto handler 'MyController'
[DefaultAnnotationHandlerMapping] Mapped URL path [/rest/*.*] onto handler 'MyController'
[DefaultAnnotationHandlerMapping] Mapped URL path [/rest/*/] onto handler 'MyController
'
I try to access: http://localhost:8080/foo/bar/baz/rest, what I see is:
WARN [PageNotFound] No mapping found for HTTP request with URI [/foo/bar/baz/rest] in DispatcherServlet with name 'spring-rest'
But when I change value to "/" from "/rest/" in Java as :
@RequestMapping(value="/*", method = RequestMethod.POST)
It then works fine.How do I fix the problem?
spring-rest-servlet.xml:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="alwaysUseFullPath" value="true"/>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="alwaysUseFullPath" value = "true" />
</bean>
Upvotes: 1
Views: 3453
Reputation: 6237
If you really want to have both /rest
and /rest/*
handled by single method, use:
@RequestMapping(value={ "/rest", "/rest/*" }, method = RequestMethod.POST)
with:
@RequestMapping(value="/*", method = RequestMethod.POST)
it works, because it accepts everything after /foo/bar/baz
, not only /rest
Upvotes: 0