title: Spring Boot, Spring Security returns a status 401 instead of 404 for "no mapping found for HTTP request"
body: <p>I am having a project using Spring Boot and Spring Security. Spring Security validate the header with the session id for every request. If the session id is invalid or expired, an error code 401 will be returned. The session id is validated before it gets to the controller.</p>
  
  <p>Now, I am facing an issue that if the user enters an invalid URL without a valid session id, still the response code is 401 because the session id is validated first. My expectation is that if the URL is invalid, an error code 404 (no mapping found for HTTP request) will be returned. In other words, I want to validate the URL before validating session id.</p>
  
  <p>Is there any way to do so because the session id in the header is validated in the GenericFilterBean before it gets to the controller?</p>
  
  <p>Any help is appreciated. Thank you.</p>