title: Custom handling for 405 error with Spring Web MVC
body: <p>In my application, I have a few RequestMappings that only allow POST. If someone happens to fire a GET request at that particular path, they get a 405 error page fed by the container (Tomcat). I can create and define a 405 error page in web.xml for customization.</p>
  
  <p>What I want: any request that would result in a 405 error should be handled in a specific controller method.</p>
  
  <p>What I've tried:</p>
  
  <ul>
  <li>a method with "method = GET" as a counterpart for each of the mappings mentioned. This works fine, but requires me to create an actual requestmapping and method for every path that only allows POST. I find this unnecessary duplication and clutter.</li>
  <li>a global 'catch' method (requestmapping /*): this does not work, as Spring takes the GET method to be a wrong call to the path specified with POST only</li>
  <li>an ExceptionHandler-annotated method to handle exceptions of class HttpRequestMethodNotSupportedException: this does not work. It seems that Spring throws and catches this exception entirely in its framework code.</li>
  <li>specify my own 405 in web.xml. This is not perfect, as I want to have customized handling rather than a static error page.</li>
  </ul>