我是靠谱客的博主 执着小蘑菇,这篇文章主要介绍ssh中spring向Action类@Autowired注入service空指针问题解决,现在分享给大家,希望可以做个参考。

使用servlet注入时,上一篇博文已经解释了,但是在使用ssh框架时,就不能用同样的方法了。

下面是解决方案:

(1)pom.xml文件中有没有引入struts2-spring-plugin包

 <!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-spring-plugin -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.5.18</version>
</dependency>

(2)struts.xml文件有没有加入

<constant name="struts.objectFactory" value="spring" />

(3)web.xml文件中有没有添加监听器和context-param


<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

 

最后

以上就是执着小蘑菇最近收集整理的关于ssh中spring向Action类@Autowired注入service空指针问题解决的全部内容,更多相关ssh中spring向Action类@Autowired注入service空指针问题解决内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(103)

评论列表共有 0 条评论

立即
投稿
返回
顶部