注入
@Autowired
ManageService manageService;
在doFilter()中添加如下代码
// 获取容器,完成注入
HttpServletRequest request = (HttpServletRequest) servletRequest;
ServletContext sc = request.getSession().getServletContext();
XmlWebApplicationContext cxt = (XmlWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(sc);
// 从容器中获取redisTemplate
if(cxt != null && cxt.getBean("manageService") != null && this.manageService == null) {
this.manageService = (ManageService) cxt.getBean("manageService");
}
在配置文件applicationContext-service.xml中添加Bean
<!--配置bena,可以让Filter使用注入,注入manageService-->
<bean id="manageService" class="com.javapandeng.service.impl.ManageServiceImpl"> </bean>
注意: 变量名称要保持一致对应