title: When URL suffixed by a file extension, Spring Restful ControllerAdvice exception handler response html
body: <p>I use @RestControllerAdvice to handle exception thrown by a controller globally, and response json string to client.  My rest controller @RequestMapping path can accept URL suffixed by a file extension. If the controller throw a exception and URL is suffixed by a known extension , the exception handler will response html instead of json. </p>
  
  <p>build.gradle</p>
  
  <pre><code>...
  dependencies {
       compile 'com.google.code.gson:gson:2.7'
       compileOnly 'org.apache.tomcat:tomcat-servlet-api:8.0.33'
       compile 'org.springframework:spring-webmvc:4.3.1.RELEASE'
  }
  </code></pre>
  
  <p>servlet-context.xml</p>
  
  <pre><code>...
      &lt;mvc:annotation-driven/&gt;
      &lt;context:component-scan base-package="com.demo"/&gt;
  ...
  </code></pre>
  
  <p>DemoController.java</p>
  
  <pre><code>@RestController
  public class DemoRestController {
      @RequestMapping(value = "/{name:.+}")
      public String doSomething(@PathVariable String name){
         throw new  RuntimeException(name);
      }
  }
  </code></pre>
  
  <p>RestExceptionHandler</p>
  
  <pre><code>@RestControllerAdvice
  public class RestExceptionHandler {
      @ExceptionHandler(Exception.class)
      public Message handleException(Exception ex, WebRequest request) {
             Message ret=new Message(System.currentTimeMillis(),ex.getMessage());
             return ret;
      }
  }
  </code></pre>
  
  <p>client</p>
  
  <pre><code>$ curl localhost:8080/abc                     //no extension, it's ok
  {"time":1479235304196,"url":"abc"}            
  $ curl localhost:8080/abc.opq                 //unknown extension, ok
  {"time":1479235545303,"url":"abc.opq"}
  $ curl localhost:8080/abc.jpg
  &lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/8.0.33 - Error report&lt;/title&gt; ...
  ...
  </code></pre>
  
  <p>the last output is html, it is not i want, what's matter?  can you help me , thank you !</p>