title: ResponseEntityExceptionHandler is not getting called when exception occurs
body: <p>I am new to spring. I am developing a REST api with spring webmvc. For Error Handling I got this link <a href="http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-rest-spring-mvc-exceptions" rel="noreferrer">http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-rest-spring-mvc-exceptions</a></p>
  
  <p>I have tried to use ResponseEntityExceptionHandler in my project . but whenever my controller throws exception it never reaches to this ResponseEntityExceptionHandler.</p>
  
  <p>Following are my code snippet</p>
  
  <p>Controller</p>
  
  <pre><code>@Controller
  @RequestMapping("/hello")
  public class HelloController {  
      private static final Logger logger = Logger.getLogger(HelloController.class);
      @RequestMapping(value="/{name}", method=RequestMethod.GET)
      public @ResponseBody String greet(@PathVariable(value = "name")String name ) throws InvalidInputException, ResourceNotFoundException{
          logger.info("start greet() "+name );
          System.out.println("start greet() "+name);
          String message = null;
          if("".equalsIgnoreCase(name))
          {
              throw new InvalidInputException("Invalid Input");
          }
          List&lt;String&gt; names = new ArrayList&lt;String&gt;();
          names.add("Harshal");
          names.add("Smitesh");
          if(names.contains(name)){
              message = "Hello "+ name;
          }else{
              throw new ResourceNotFoundException("Requested Resource not found");
          }
          System.out.println("end greet");
          logger.info("end greet()");
          return message;
      }
  }
  </code></pre>
  
  <p>Exceptions </p>
  
  <pre><code>package com.practice.errorhandlerdemo.exception;
  
  public class InvalidInputException extends RuntimeException{
      private static final long serialVersionUID = 5489516240608806490L;
      public InvalidInputException() {
          super("Invalid Input");
      }
      public InvalidInputException(String message) {
          super(message);
      }
  }
  
  package com.practice.errorhandlerdemo.exception;
  
  public class ResourceNotFoundException extends RuntimeException {
      private static final long serialVersionUID = -4041009155673754859L;
      public ResourceNotFoundException() {
          super("requested resource not found");
      }
      public ResourceNotFoundException(String message) {
          super(message);
      }
  }
  </code></pre>
  
  <p>exceptionhandler</p>
  
  <pre><code>@ControllerAdvice
  public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
      private static final Logger logger = Logger.getLogger(RestResponseEntityExceptionHandler.class);
      @ExceptionHandler(value={ResourceNotFoundException.class})
      @ResponseStatus(value=HttpStatus.NOT_FOUND)
      protected ResponseEntity&lt;Object&gt; handleResourceNotFound(RuntimeException ex, WebRequest request){
          logger.info("start handleResourceNotFound()");
          String bodyOfResponse = "Requested resource does not found";
          HttpHeaders httpHeaders = new HttpHeaders();
          httpHeaders.setContentType(MediaType.APPLICATION_JSON);
          return handleExceptionInternal(ex, bodyOfResponse, httpHeaders, HttpStatus.NOT_FOUND, request);
      }
  
      @ExceptionHandler(value={InvalidInputException.class})
      @ResponseStatus(value=HttpStatus.BAD_REQUEST)
      protected ResponseEntity&lt;Object&gt; handleInvalidInput(RuntimeException ex, WebRequest request){
          logger.info("start handleInvalidInput()");
          String bodyOfResponse = "Invalid Input";
          HttpHeaders httpHeaders = new HttpHeaders();
          httpHeaders.setContentType(MediaType.APPLICATION_JSON);
          return handleExceptionInternal(ex, bodyOfResponse, httpHeaders, HttpStatus.BAD_REQUEST, request);
      }
  }
  </code></pre>
  
  <p>dispatcher servlet</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:p="http://www.springframework.org/schema/p"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-4.0.xsd"&gt;
  
     &lt;context:component-scan base-package="com.practice.errorhandlerdemo.controller"/&gt;
     &lt;context:annotation-config/&gt;  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;web-app&gt;
      &lt;display-name&gt;ErrorHandlerDemo&lt;/display-name&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/my-servlet.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>