在action中 使用@Resource注解service层 总是得到null
本帖最后由 c305600647 于 2013-03-09 17:32:54 编辑
在action中 使用@Resource注解service层 总是得到null dao层和service层中的都能正常得到值
但是使用getBean()却可以得到service什么原因求指教。。。
架构是s2sh纯注解。
@Service("serviceFaceImpl")
public class ServiceFaceImpl implements ServiceFace {
@Resource
private UserLoginService userLoginService;
@Resource
private LeaveService leaveService;
@Override
public void setUserLoginService(UserLoginService userLoginService) {
this.userLoginService = userLoginService;
}
@Override
public UserLoginService getUserLoginService() {
return userLoginService;
}
@Override
public LeaveService getLeaveService() {
return leaveService;
}
@Override
public void setLeaveService(LeaveService leaveService) {
this.leaveService = leaveService;
}
}
action 中:
public class WebBaseAction extends ActionSupport implements ServletRequestAware,ServletResponseAware {
/**
*
*/
private static final long serialVersionUID = 1L;
//public ServiceFace serviceFace;
protected static Logger log = Logger.getLogger(WebBaseAction.class);
public HttpServletRequest request ;
public HttpServletResponse response ;
@Resource
protected ServiceFace serviceFace;//这个无法得到
//protected ServiceFace serviceFace = (ServiceFace) SpringIoc.getApplicationContext().getBean("serviceFaceImpl");//这个可以得到serviceFace
public ServiceFace getServiceFace() {
return serviceFace;
}
public void setServiceFace(ServiceFace serviceFace) {
this.serviceFace = serviceFace;
}
------解决方案--------------------引入struts2-spring-plugin-2.3.15.1.jar就可以了,对应版本的struts引入的版本不一样