I'm working on setting up a REST api using Java/Spring/Maven in a JBoss servlet engine and utilising MultiActionController.
What I want to do is to group requests to a Single controller
for example: all /requestA goes to Controller a
, that has several methods for different request, like - /requestA/add.do goes to add-function
/requestA/delete.do goes to delete-function.
I've been reading the Spring documentation: http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch18s02.html and http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch16s03.html#mvc-controller-multiaction
But I've got some problems in the dispatcher configuration in the xml. Does anyone know of a good example how to accomplish this in Spring MVC.
springapp-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean name="/test/*.do" class="org.test.TestControllerA" />
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>springTest</display-name>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
and the Java Controller
public class TestControllerA extends MultiActionController {
@RequestMapping("/TEST")
public ModelAndView add(HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("Test42");
return new ModelAndView();
}
}
You are missing the servlet-mapping
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Your urls have the extension *.do
but it is not mapped to springapp
. So add the above configuration to your web.xml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.