springMVC和spring上下文的关系

springMVC继承了spring的servletcontext上下文,

所以, controller里的@Resource注入可以用以下替代

@Resource
private IUserService userService;

替代:

WebApplicationContext ac1 = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
WebApplicationContext ac2 = RequestContextUtils.getWebApplicationContext(request);
//IUserService userService = (IUserService)ac1.getBean("userService");
IUserService userService = (IUserService)ac2.getBean("userService");
List<User> users = userService.getAllUser();
request.setAttribute("users", users);
上一篇:hdu5442(2015长春赛区网络赛1006)后缀数组+KMP /最小表示法?


下一篇:python 正则表达式 -- IP地址验证