在action类中希望@resourse注解自动注入service类中的实例。但是运行时报java.lang.NullPointerException错误。
搜索发现是没有加入struts2-spring-plugin.jar的jar包。加入jar包后,发现出现了404的错误。那么一定是web.xml的错误了。
搜索后发现要加如下面语句:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 加载spring配置文件applicationContext.xml -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>