rest - url-pattern doesn't work in spring mvc application -
spring 3.2 in apache tomcat
web.xml:
<?xml version="1.0" encoding="utf-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring/root-context.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring/rest-servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app> rest-servlet-context.xml:
<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <annotation-driven /> <context:component-scan base-package="com.*" /> </beans:beans> my controller:
@controller @requestmapping(value = "/rest/person") public class personcontroller { @requestmapping(value = "/test") @responsebody public string gettest() { homecoming "test controller"; } } when phone call /localhost:8080/rest/person/test, 404 error (page not found).
however, when alter url-pattern in web.xml file to:
<url-pattern>/*</url-pattern> it works fine.
how can create first url-pattern work??
remove rest requestmapping, e.g. alter to
@requestmapping(value = "/person") the reason url-pattern contains rest/*, doing map url rest/rest/person/test , not rest/person/test.
spring rest spring-mvc url-pattern
No comments:
Post a Comment