------------------------------------------------
环境:Spring 4, Resteasy 3.0.6 and Tomcat 7
问题:所有的REST服务都是404错误
官方给出的解决方案:https://issues.jboss.org/browse/RESTEASY-1012
-------------------------------------------------
经过本人验证测试通过,改动如下:
1、在maven配置文件pom.xml中添加servlet3(spring4是基于servlet3为基准的)
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
2、重写ContextLoaderListener(自己实现)
import javax.servlet.ServletContext; import org.jboss.resteasy.plugins.spring.SpringContextLoaderSupport; import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.ContextLoaderListener; public class MyContextLoaderListener extends ContextLoaderListener { private SpringContextLoaderSupport springContextLoaderSupport = new SpringContextLoaderSupport(); @Override protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext configurableWebApplicationContext) { super.customizeContext(servletContext, configurableWebApplicationContext); this.springContextLoaderSupport.customizeContext(servletContext, configurableWebApplicationContext); } }
3、修改web.xml中的ContextLoaderListener
<!-- <listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener> -->
<listener>
<listener-class>com.xxx.xxx.MyContextLoaderListener</listener-class>
</listener>
ok,就改这3个地方就可以解决此404问题了!