Hi everyone,
I'm having a frustrating time with Spring 3 MVC trying to build RESTful web services.
I want RESTful URLs, e.g. "my.domain.com/items", not "my.domain.com/items.do" or anything else that includes an extension. My web.xml includes the following. Note the URL pattern:
<servlet>
<servlet-name>addictedWebServices</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>addictedWebServices</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
My addictedWebServices-servlet.xml includes the following view resolvers:
<bean id="viewResolver2" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
And one of my controllers includes the following method:
@RequestMapping(value = "/shoutouts", method = RequestMethod.POST)
public String post(@RequestBody ShoutOut shoutOut) {
logger.info("In shout outs controller: post().");
shoutOutDao.save(shoutOut);
return "OK";
}
Everything in the method executes fine when I post to this URL, but when Spring goes to display /WEB-INF/jsp/OK.jsp
, I get the following warning:
2010-06-22 18:34:51,993 WARN [http-8080-2] org.springframework.web.servlet.PageNotFound (DispatcherServlet.java:965) - No mapping found for HTTP request with URI [/addicted/WEB-INF/jsp/OK.jsp] in DispatcherServlet with name 'addictedWebServices'
And Tomcat throws up a 404. It appears the DispatcherServlet handles the URL because my servlet-mapping's url-pattern is set to /*. How can I get around this? Everything executes fine if I change the servlet-mapping url-pattern to *.do and then make all the related changes to my Spring MVC annotations.
Thanks for your help!