chn_wwz
2016-05-04 02:13SSH 框架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条回答
为你推荐
- SSH框架中的有关数据库的问题
- struts
- spring
- ssh
- hibernate
- 0个回答
- SSH做登录时,service不能注入到action,这是为什么啊
- struts
- spring
- hibernate
- 0个回答
- ssh中 no result defined for action and result error
- 1个回答