ssh中spring向Action类@Autowired注入service空指针问题解决

版权声明:转载请注明作者:sust_ly https://blog.csdn.net/pycharm_u/article/details/84950107

使用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>

猜你喜欢

转载自blog.csdn.net/pycharm_u/article/details/84950107