拦截器@Service注入失效解决方式

if (redisUtils == null) {//解决service为null无法注入问题
System.out.println("redisUtils is null!!!");
BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
redisUtils = (RedisUtils) factory.getBean("redisUtils");
}

原因:拦截器加载的时间点在springcontext之前,所以在拦截器中注入自然为null
posted @ 2018-06-28 10:27  rock_turf  阅读(473)  评论(0编辑  收藏  举报