SSH框架整合,Spring只使用核心模块IOC
applicationContext.xml配置如下:
<bean id="userServiceImpl" class="com.founder.ssj.service.impl.UserServiceImpl"    >
</bean>
<bean id="loginAction"      class="com.founder.ssj.action.user.LoginAction"       >
    <property name="userService">
        <ref bean="userServiceImpl"/>
    </property>
</bean>
web.xml配置如下:
<!-- Spirng配置文件位置 -->
contextConfigLocation
classpath:applicationContext.xml
<!-- 加载 Spring -->
org.springframework.web.context.ContextLoaderListener
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
struts配置如下:
<package name="main"  extends="struts-default" >
    <action name="login" class="com.founder.ssj.action.user.LoginAction" >
        <result name="success">/index.jsp</result>
        <result name="fail">/login.jsp</result>
    </action>
</package>
Action 代码:GET SET 都全了
public class LoginAction extends ActionSupport{
//为何没有被注入?
private IUserService userService;
private String username;
private String password;
public LoginAction() {
    super();
    System.out.println(2);
}
/**
 * 
 */
private static final long serialVersionUID = 835443313500278156L;
@Override
public String execute(){
    String state="fail";
    try {
        if(userService.login(username, password)){
            state="success";
        };
    } catch (Exception e) {
        e.printStackTrace();
    }
    return state;
}
每当执行到该方法时,userService 对象都是空?
为什么呢?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
在struts.xml中加入
<constant name="struts.objectFactory" value="spring" />
然后把 <action name="login" class="com.founder.ssj.action.user.LoginAction" >
改成<action name="login" class="loginAction" >