现象:
action中的@autowired注入service或dao失败,报空指针异常
原因:
造成该问题的原因是你并没有做好spring和jersey的整合工作,检查你的web.xml文件,jersey的配置肯定是下面这样
-
<servlet>
-
<servlet-name>JerseyServlet</servlet-name>
-
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
-
<init-param>
-
<param-name>com.sun.jersey.config.property.packages</param-name>
-
<param-value>com.demo</param-value>
-
</init-param>
-
<load-on-startup>1</load-on-startup>
-
</servlet>
-
<servlet-mapping>
-
<servlet-name>JerseyServlet</servlet-name>
-
<url-pattern>/rest/*</url-pattern>
-
</servlet-mapping>
解决的办法:
首先你需要确认是否引入了jersey-spring.jar的jar包,如果没有,请先导入。
其次请将jersey的配置改成下面这样,
-
<servlet>
-
<servlet-name>JerseyServlet</servlet-name>
-
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
-
<init-param>
-
<param-name>com.sun.jersey.config.property.packages</param-name>
-
<param-value>com.demo</param-value>
-
</init-param>
-
<load-on-startup>1</load-on-startup>
-
</servlet>
-
<servlet-mapping>
-
<servlet-name>JerseyServlet</servlet-name>
-
<url-pattern>/rest/*</url-pattern>
-
</servlet-mapping>
大家可能已经看到,区别在于servlet-class的类。
http://blog.csdn.net/superick/article/details/39400971
阅读(621) | 评论(0) | 转发(0) |