spring无法注入

struts2整合spring3启动不报错并且Spring成功初始化 :信息: Initializing Spring root WebApplicationContext

但是在action里面无法使用spring无法注入的dao或者service。

解决办法:

1、没加入struts2-spring-plugin.jar包

2、检查配置文件是否真的没有问题

3、在struts.xml里面将action配置的class路径修改成 在application.xml配置的对应action的id属性

修改前:


    
[html] view plain copy
  1. <struts>
  2. <packagename="budget"extends="struts-default">
  3. <actionname="login"class="com.bean.LoginAction"method="verifyUser">
  4. <resultname="success">finance_center/center.jsp</result>
  5. <resultname="error">login/error.jsp</result>
  6. </action>
  7. </struts>

修改后:

[html] view plain copy
  1. <struts>
  2. <packagename="budget"extends="struts-default">
  3. <actionname="login"class="loginAction"method="verifyUser">
  4. <resultname="success">finance_center/center.jsp</result>
  5. <resultname="error">login/error.jsp</result>
  6. </action>
  7. <struts>

spring配置文件不变

    
[html] view plain copy
  1. <beanid="loginAction"class="com.action.LoginAction"scope="prototype">
  2. <propertyname="service">
  3. <refbean="loginService"/>
  4. </property>
  5. </bean>

第三个原因很坑爹啊。。。费力我两个小时啊。。。。。。。

你可能感兴趣的:(spring)