当前位置: 代码迷 >> Java Web开发 >> spring 流入失败!
  详细解决方案

spring 流入失败!

热度:1614   发布时间:2013-02-25 21:09:07.0
spring 注入失败!!!!!!!!
applicationContext.xml
XML code
<bean id="userDao" class="com.quxiuna.dao.impl.UserDaoImpl">        <property name="sessionFactory">            <ref local="sessionFactory" />        </property>    </bean>    <bean id="userService" class="com.quxiuna.service.impl.UserServiceImpl">        <property name="userDao">            <ref local="userDao" />        </property>    </bean>    <bean id="loginAction" class="com.quxiuna.struts.action.login.LoginAction" scope="prototype">        <property name="userService">            <ref local="userService" />        </property>    </bean>

struts.xml
XML code
<struts>    <constant name="struts.objectFactory" value="spring" />    <constant name="struts.devMode" value="true" />    <constant name="struts.objectFactory.spring.autoWire" value="type" />    <include file="struts-default.xml"/>    <include file="com/quxiuna/struts/action/login/loginAction.xml" /></struts> 

loginAction.xml
XML code
<struts>         <package name="login" extends="struts-default" namespace="/login">             <action name="loginAction" class="com.quxiuna.struts.action.login.LoginAction">                 <result name="success">/sendSuccss.jsp</result>         </action>      </package></struts> 

web.xml
XML code
     <context-param>       <param-name>contextConfigLocation</param-name>       <param-value>           /WEB-INF/applicationContext*.xml       </param-value>    </context-param>    <listener>                 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>

UserServiceImpl.java
Java code
public class UserServiceImpl implements UserService {    public UserDAO userDao;    public UserDAO getUserDao() {        return userDao;    }    public void setUserDao(UserDAO userDao) {        this.userDao = userDao;    }


Java code
package com.quxiuna.struts.action.login;import java.util.Map;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;import com.quxiuna.hibernate.po.RbacUser;import com.quxiuna.service.UserService;import com.quxiuna.util.Constants;public class LoginAction extends ActionSupport {        private static final long serialVersionUID = -1640288447822607013L;        private String name;    private String password;    private String message;    public UserService userService;    public String getName() {        return name;    }            public void setName(String name) {        this.name = name;    }    public String getPassword() {        return password;    }    public void setPassword(String password) {        this.password = password;    }        @SuppressWarnings("unchecked")    public String execute() {        RbacUser user = userService.login(name, password);        if (user != null) {            ActionContext ctx = ActionContext.getContext();             Map session = ctx.getSession();             session.put(Constants.SESSSION_NAME, name);            return SUCCESS;        } else {            message = "用户名或密码错误!";             return ERROR;        }    }    public String getMessage() {        return message;    }    public void setMessage(String message) {        this.message = message;    }    public UserService getUserService() {        return userService;    }    public void setUserService(UserService userService) {        this.userService = userService;    }}
  相关解决方案