标签:lan exce rda 定义 对象 getbean public print china
public class SpringContextUtils implements ApplicationContextAware {
private static ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext context)
throws BeansException {
SpringContextUtils.context = context;
}
public static ApplicationContext getContext(){
return context;
}
}
<!--Spring中bean获取的工具类-->
<bean id="springContextUtils" class="com.zker.common.util.SpringContextUtils" />
/**
* 利用Ajax实现注册的用户名重复性校验
* @return
*/
public String ajaxRegister() throws IOException {
UserDao userDao = (UserDao)SpringContextUtils.getContext().getBean("userDao");
if (userDao.findAdminByLoginName(loginName) != null
|| userDao.findUserByLoginName(loginName) != null) {
message.setMsg("用户名已存在");
message.setStatus(false);
} else {
message.setMsg("用户名可以注册");
message.setStatus(true);
}
return "register";
}
如何手动获取Spring容器中的bean(ApplicationContextAware 接口)
标签:lan exce rda 定义 对象 getbean public print china
原文地址:http://www.cnblogs.com/deng-cc/p/6373670.html