Springboot2.2打成war包过滤器或者拦截器注入失败

编程

Filter里面注入失败。

解决方法在init初始化这里对Service进行手动注入
 

public class RESTApiAuthenticationFilter implements Filter {

protected Logger logger = LoggerFactory.getLogger(getClass());

@Autowired

private ApiUserService apiUserService;

@Autowired

private SignaConfig signaConfig;

@Override

public void init(FilterConfig filterConfig) {

logger.info("RESTApiAuthentication filter has been launched!");

//手动注入

BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext());

signaConfig = factory.getBean(SignaConfig.class);

apiUserService = factory.getBean(ApiUserService.class);

}

@Override

public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse,

FilterChain chain) throws IOException, ServletException {

}

@Override

public void destroy() {

// TODO Auto-generated method stub

}

}


    
    在Filter 初始化的时候手动注入即可。
    这个问题已经馋了我三天三夜了

以上是 Springboot2.2打成war包过滤器或者拦截器注入失败 的全部内容, 来源链接: utcz.com/z/517966.html

回到顶部