title: How to customize DefaultHandlerExceptionResolver logic?
body: <p>I want to customize <code>DefaultHandlerExceptionResolver</code> in my Spring Boot application but custom implementation was never reached when exception was occurred.</p>
  
  <p><strong>build.gradle</strong></p>
  
  <pre><code>buildscript {
      ext {
          springBootVersion = '2.1.1.RELEASE'
      }
      repositories {
          mavenCentral()
      }
  }
  
  plugins {
      id 'java'
      id 'org.springframework.boot' version '2.1.1.RELEASE'
      id 'io.spring.dependency-management' version '1.0.6.RELEASE'
      id 'io.franzbecker.gradle-lombok' version '1.14'
  }
  
  lombok {
      version = '1.18.4'
      sha256 = ""
  }
  
  group = 'ua.com.javaman'
  version = '0.0.1-SNAPSHOT'
  sourceCompatibility = 1.8
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      implementation('org.springframework.boot:spring-boot-starter-web')
  }
  </code></pre>
  
  <p><strong>Application.java</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  @RestController
  @Configuration
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      @ResponseBody
      @PostMapping("/mouse")
      public Mouse postMouse(@Valid Mouse mouse) {
          // mouse creation logic
          return mouse;
      }
  
      @Bean
      public HandlerExceptionResolver customHandlerExceptionResolver() {
          return new CustomExceptionHandlerResolver();
      }
  }
  </code></pre>
  
  <p><strong>Mouse.java</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Value
  public class Mouse {
      private final Long id;
      @NotEmpty
      @Min(2)
      private final String name;
  }
  </code></pre>
  
  <p><strong>CustomExceptionHandlerResolver.java</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public class CustomExceptionHandlerResolver extends DefaultHandlerExceptionResolver {
      @Override
      protected ModelAndView handleBindException(
          BindException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler
      ) throws IOException {
          System.out.println("In CustomExceptionHandlerResolver");
          response.sendError(HttpServletResponse.SC_BAD_REQUEST);
          return new ModelAndView();
      }
  }
  </code></pre>
  
  <p><strong>Package structure</strong></p>
  
  <pre><code>.
  ├── build.gradle
  ├── gradle
  │   └── wrapper
  │       ├── gradle-wrapper.jar
  │       └── gradle-wrapper.properties
  ├── gradlew
  ├── gradlew.bat
  ├── LICENSE
  ├── README.md
  ├── settings.gradle
  └── src
      └── main
          └── java
              └── ua
                  └── com
                      └── javaman
                          └── exception_handling
                              ├── Application.java
                              ├── CustomExceptionHandlerResolver.java
                              └── Mouse.java
  </code></pre>
  
  <p>When I invoke application with wrong values for <code>Mouse</code> entity, for example, </p>
  
  <pre><code>POST localhost:8080/mouse?name=1
  </code></pre>
  
  <p>than <a href="https://github.com/spring-projects/spring-framework/blob/78a6429c3295ecdbc35b064f7ebfa568079856df/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java#L488-L492" rel="noreferrer"><code>handleBindException()</code></a> method in <code>DefaultHandlerExceptionResolver</code> is invoked but not in my <code>CustomExceptionHandlerResolver</code>.</p>
  
  <p><strong>How can I handle <code>BindException</code> with my <code>CustomExceptionHandlerResolver</code>?</strong></p>