title: Spring and @Autowired on a DelegatingFilterProxy
body: <p>I'm trying to inject a spring bean into a filter, but can't make it work.</p>
  
  <p>The bean injected is always "null". I succeed autowiring this same bean in Controllers and HandlerInterceptors so it's correctly annotated. </p>
  
  <p>The filter class is under the same base-package of the rest of Controllers. </p>
  
  <p>This is the relevant part of my web.xml</p>
  
  <pre><code>  &lt;filter&gt;
      &lt;filter-name&gt;CheckSession&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
      &lt;filter-name&gt;CheckSession&lt;/filter-name&gt;
      &lt;url-pattern&gt;/panel/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>This is the code for the filter</p>
  
  <pre><code>@Component 
  public class CheckSession extends OncePerRequestFilter implements Filter {
  
      @Autowired private Usuario usuario;
  
      @Override
      protected void doFilterInternal(
          HttpServletRequest request,
          HttpServletResponse response, FilterChain chain)
      throws ServletException, IOException {
  
          //  always null
          System.out.println("autowired " + usuario);
          chain.doFilter(request,  response);
      }
  }
  </code></pre>
  
  <p>The filter is triggering on every request. </p>
  
  <p>These are the annotations in the "Usuario" bean</p>
  
  <pre><code>@Component
  @Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
  public class Usuario implements java.io.Serializable { ... }
  </code></pre>
  
  <p>What am i missing? Thanks!</p>