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属性
修改前:
- <struts>
- <packagename="budget"extends="struts-default">
- <actionname="login"class="com.bean.LoginAction"method="verifyUser">
- <resultname="success">finance_center/center.jsp</result>
- <resultname="error">login/error.jsp</result>
- </action>
- </struts>
修改后:
- <struts>
- <packagename="budget"extends="struts-default">
- <actionname="login"class="loginAction"method="verifyUser">
- <resultname="success">finance_center/center.jsp</result>
- <resultname="error">login/error.jsp</result>
- </action>
- <struts>
spring配置文件不变
- <beanid="loginAction"class="com.action.LoginAction"scope="prototype">
- <propertyname="service">
- <refbean="loginService"/>
- </property>
- </bean>
第三个原因很坑爹啊。。。费力我两个小时啊。。。。。。。