Unable to autowire the service inside my authentication filter in Spring

后端 未结 6 2174
无人及你
无人及你 2020-11-29 23:11

I am trying to authenticate user by token, But when i try to auto wire one my services inside the AuthenticationTokenProcessingFilter i get null pointer excepti

6条回答
  •  眼角桃花
    2020-11-29 23:36

    I just made it work by adding

    SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);

    I am unsure why we should do this even when i tried adding explicit qualifier. and now the code looks like

    public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain chain) throws IOException, ServletException {
    
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    
            @SuppressWarnings("unchecked")
            Map parms = request.getParameterMap();
    
            if (parms.containsKey("token")) {
    

提交回复
热议问题