概述:最近做的两个项目都用到了,所以想着把它整理起来方便以后用,不多说了,现在就将代码附上
我的活动平台filter:
public class SysFilter implements javax.servlet.Filter {
private IUserService userService;
private IBasDao basDao;
@Override//在其初始化的时候获取
public void init(FilterConfig filterConfig) throws ServletException {
//这里面才是关键所在
ServletContext context = filterConfig.getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
userService = (IUserService) ctx.getBean("userService");
basDao =(IBasDao)ctx.getBean("basDao");
//To change body of implemented methods use File | Settings | File Templates.
}
我的CRM项目Servlet:
public void init(ServletConfig servletConfig) throws ServletException { ServletContext servletContext = servletConfig.getServletContext(); WebApplicationContext webApplicationContext = WebApplicationContextUtils .getWebApplicationContext(servletContext); userService = (IUserService) ctx.getBean("userService"); 上面是我自己搞的,稍后我会将公司的也写上去。
本文出自 “小博客” 博客,请务必保留此出处http://9686567.blog.51cto.com/9676567/1591717
原文地址:http://9686567.blog.51cto.com/9676567/1591717