Trying to add a restful web service call to an existing Spring 3.11 MVC application, but the app has a url mapping in web.xml for spring like this:
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
So everything basically needs to end in .html
I would like for my web service to not have to do that - ideally by using a unique context/subfolder for my web services, such as /restful for example.
But I am not sure how to get it to work...
So if my controller was like this:
@ResponseBody
@RequestMapping(value="restful/test/{test}",method = RequestMethod.GET)
public String test(@PathVariable String test)
{
return "OK"+test;
}
And I wanted to access it by: localhost/blah/restful/test/text (no .html anywhere, and where blah is the application context) how should I handle the url-pattern in the web.xml -- without interfering with anything already existing in the app?
When I add another url-pattern like this:
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/restful/*</url-pattern>
</servlet-mapping>
And try to access localhost/blah/restful/test/text, I get a 404 error.
The other part of the web-xml for servlet looks like this:
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
And the view resolver in that spring-mvc.xml file is like this:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>