title: How to execute a filter on specific request in spring mvc?
body: <hr>
  
  <h2>Below is the Filter.</h2>
  
  <pre><code>@Component
  public class TestFilter extends GenericFilterBean {
  
  @Override
  public void doFilter(
    ServletRequest request, 
    ServletResponse response,
    FilterChain chain) throws IOException, ServletException {
      chain.doFilter(request, response);
      HttpServletRequest httpRequest = (HttpServletRequest) request;
      System.out.println("token is: "+httpRequest.getHeader("token"));
  }    
  }
  </code></pre>
  
  <hr>
  
  <p>Below is the resource
  I want to execute above filter for the second request only.</p>
  
  <h2>How it can be done, plz help....</h2>
  
  <pre><code>@RestController
  public class UserResourceImpl implements UserResource {
  
  private final UserDao userDao;
  private final AuthenticationService authenticationService;
  @Autowired
  public UserResourceImpl(final UserDao userDao,final AuthenticationService authenticationService) {
  this.userDao = userDao; 
  this.authenticationService = authenticationService;
  }
  
  @Override
  @RequestMapping(method = RequestMethod.POST, value = "/api/user", produces = "application/json")
  public ResponseEntity&lt;?&gt; create(final User user) {
      userDao.save(user);
      return new ResponseEntity&lt;&gt;("", HttpStatus.OK);
  }
  
  @Override
  @RequestMapping(method = RequestMethod.GET, value = "/api/user", produces = "application/json")
  public ResponseEntity&lt;?&gt; getUsers(final User user) {
  
  
  enter code here
      // how to execute the above filter for this request only ?
  
      return new ResponseEntity&lt;&gt;("", HttpStatus.OK);
  }
  
  }
  </code></pre>