关于网友提出的“ struts和spring整合的时候 struts无法注入”问题疑问,本网通过在网上对“ struts和spring整合的时候 struts无法注入”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: struts和spring整合的时候 struts无法注入
描述: strut.xml
<>
class="com.talkweb.web.action.LoginAction">
/admin/index.jsp
/index.jsp
/index.jsp
aplicationcontext.xml
?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c>
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">
autoLoadResourceObject
com.talkweb.web.servlet.ResourceAutoLoader
0
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
*.action
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath*:applicationContext.xml
/index.jsp
login.action
package com.talkweb.web.action;
import com.talkweb.model.Student;
import com.talkweb.service.BaseService;
import com.talkweb.web.commom.BaseAction;
public class LoginAction extends BaseAction{
private static final long serialVersionUID = 1L;
private BaseService adminService;
public Student getModel() {
// TODO Auto-generated method stub
return null;
}
/**
* 登陆
* @return
* @throws Exception
*/
public String login(){
System.out.println("----------------");
String loginName = getRequestParmeterByTrim("loginName");
String password = getRequestParmeter("password");
this.getRequest().setAttribute("loginName",loginName);
if(null == loginName || "".equals(loginName)){
this.getRequest().setAttribute("msg","用户名不能为空!");
return "failure";
}else{
adminService.add();
return "success";
}
}
public BaseService getAdminService() {
return adminService;
}
public void setAdminService(BaseService adminService) {
this.adminService = adminService;
}
}
解决方案1:?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c//www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
在applictioncontext.xml中加入adminService的依赖对象,你adminService需要依赖adminDao...
然后adminDao依赖dateBase,都要配置
解决方案2: 需要在strut.xml 的标签下
加入
spring才能集成
解决方案3: http://topic.csdn.net/u/20110815/14/7c259888-1d1b-4be8-8a39-cfaffc416d66.html
解决方案4: 你的acti
以上介绍了“ struts和spring整合的时候 struts无法注入”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2184636.html