简单介绍一下了 呵呵
在我们的项目中,可能需要单独使用servlet,而这个servlet又需要去获取spring的配置信息,来获得数据库中的数据。
这里需要获取WebApplicationContext ,获得了他就可以获取bean容器里面的bean了。
如这里的user ,OK了!就这样!
在我们的项目中,可能需要单独使用servlet,而这个servlet又需要去获取spring的配置信息,来获得数据库中的数据。
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- ServletContext application;
- WebApplicationContext wac;
- application = getServletContext();
- wac = WebApplicationContextUtils.getWebApplicationContext(application);//获取spring的context
- UserInfoDAOImpl user = (UserInfoDAOImpl) wac.getBean("userInfoDAO");
- PrintWriter out = response.getWriter();
- out.print(user.getAllUser().size());
- out.flush();
- out.close();
- }
这里需要获取WebApplicationContext ,获得了他就可以获取bean容器里面的bean了。
如这里的user ,OK了!就这样!