title: Spring @ComponentScan exclude/include filters
body: <p>As a good practice in a Spring MVC application, the Web configuration should pick up only the "front-end" components, such as <code>@Controller</code> or <code>@RestController</code>.<br>
  Every other bean should be picked up by the Root application context.</p>
  
  <p>I've defined the Web configuration as follow (keep in mind I don't need the <code>@EnableMvc</code> annotation, as it extends <code>WebMvcConfigurationSupport</code>)</p>
  
  <pre><code>@Configuration
  @ComponentScan(
          basePackages = { ... },
          useDefaultFilters = false,
          includeFilters = @Filter({
                  Controller.class,
                  ControllerAdvice.class}))
  </code></pre>
  
  <p>And the Root configuration as follows.</p>
  
  <pre><code>@Configuration
  @ComponentScan(
          basePackages = { ... },
          excludeFilters = @Filter({
                  Controller.class,
                  ControllerAdvice.class}))
  </code></pre>
  
  <p>I've defined two <code>@RestControllerAdvice</code> classes, the first one catches all generic <code>Exception</code>(s), the second one catches a more specific <code>ServiceException</code>.</p>
  
  <p>When throwing a <code>ServiceException</code>, the specific adviser is never called, instead only the generic one is picked. Base packages are the same in both configuration classes.</p>
  
  <p>Do I need to specify also <code>RestControllerAdvice</code> on the exclude and include filters? Or am I missing something else?</p>
  
  <p>Edit:</p>
  
  <p>Both <code>@RestControllerAdvice</code> are without <code>basePackeges</code> or any specific criteria.
  And the <code>ServiceException</code> one is actually found and registered.</p>
  
  <p>If I move the exception handler to the working handler than it is called.
  This is how I got it working. If I move the <code>ServiceException</code> handler in a separate class it is no more invoked.</p>
  
  <pre><code>@RestControllerAdvice
  public class GlobalRestControllerAdviser extends ResponseEntityExceptionHandler {
  
      @Override
      protected ResponseEntity&lt;Object&gt; handleBindException(
              final BindException ex,
              final HttpHeaders headers,
              final HttpStatus status,
              final WebRequest request) {
          return new ResponseEntity&lt;Object&gt;(
                  buildPresentableError(ex.getAllErrors().get(0)),
                  HttpStatus.BAD_REQUEST);
      }
  
      @ExceptionHandler(ServiceException.class)
      protected Response&lt;?&gt; handleServiceException(final ServiceException e) {
          ...
      }
  
      @ExceptionHandler(Exception.class)
      protected ResponseEntity&lt;Object&gt; handleGenericException(final Exception ex) {
          ...
      }
  }
  </code></pre>
  
  <p>Seems like the most generic <code>ExceptionHandler</code> is overriding the more specific one.</p>