在filter中获取spring容器中的bean对象
在工作中的项目需要,要在filter中使用服务接口,但是采用传统的new 和注入方式都是空指针异常,最后的解决方式是@Overridepublic void init(FilterConfig config) throws ServletException {ServletContext context = config.getServletContext();
·
在工作中的项目需要,要在filter中使用服务接口,但是采用传统的new 和注入方式都是空指针异常,最后的解决方式是
@Override
public void init(FilterConfig config) throws ServletException {
ServletContext context = config.getServletContext();
ApplicationContext ac = WebApplicationContextUtils .getWebApplicationContext(context);
userService1 = (UserService)ac.getBean("userService");
}
更多推荐
已为社区贡献1条内容
所有评论(0)