chn_wwz
chn_wwz
2016-05-04 02:13

SSH 框架action中注入service失败 service一直是null

//在听取建议后的第一次修改

@Resource(name="userService") 
private UserService userService;

public String login(){
    if(Validators.isEmpty(userName) || Validators.isEmpty(password)){
        return "error";
    }
    boolean flag = false;
    try{
        flag = userService.login(userName, password);
    }catch(Exception e){
        System.out.println(e.getMessage());
    }
    if(flag){
        return "success";
    }else{
        return "failure";
    }
}

//userService的注入
public void setUserService(UserService userService) {
    this.userService = userService;
}

applicationContext.xml中的配置如下

<bean id="loginAction" class="com.ssh.action.LoginAction" scope="singleton">
    <property name="userService" ref="userService" />
</bean>

<bean id="userService" class="com.ssh.service.UserServiceImpl">
</bean>

    在web.xml 中增加spring 配置:
    <listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener> 
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>


但是还是取不到userService
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答