基于Annotation的Struts2+Spring3, Spring无法向acition中注入service
我在整合环境 Struts2.2.1 + Spring3.1.2 时,我的UserAction 的第16行user = userService.getUserByID("1");
userService始终为null,报
NullPointerException ,不知如何回事,请大侠帮忙看看,谢谢!
所用lib:
aopalliance-1.0.jar
aspectjrt-1.7.0.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.1.1.jar
freemarker-2.3.16.jar
javassist-3.11.0.GA.jar
log4j-1.2.14.jar
ognl-3.0.jar
spring-aop-3.1.2.RELEASE.jar
spring-asm-3.1.2.RELEASE.jar
spring-beans-3.1.2.RELEASE.jar
spring-context-3.1.2.RELEASE.jar
spring-core-3.1.2.RELEASE.jar
spring-expression-3.1.2.RELEASE.jar
spring-jdbc-3.1.2.RELEASE.jar
spring-orm-3.1.2.RELEASE.jar
spring-tx-3.1.2.RELEASE.jar
spring-web-3.1.2.RELEASE.jar
struts2-convention-plugin-2.2.1.jar
struts2-core-2.2.1.jar
xwork-core-2.2.1.jar
---web.xml------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>myWebApp</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 配置spring的监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<!-- 开启监听 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置Struts2 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>struts.devMode</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
---Action-------------------------------------------------------------
1 package com.ibm.action;
2 import javax.annotation.Resource;
3 import org.apache.struts2.convention.annotation.Action;
4 import com.opensymphony.xwork2.ActionSupport;
5 import com.ibm.service.UserService;
6 import com.ibm.User;
7 public class UserAction extends ActionSupport {
8
9 private User user;
10
11 @Resource(name="userService")
12 private UserService userService;
13
14 @Action("/user/detail")
15 public String detail() throws Exception {
16 user = userService.getUs