title: How to exclude a @Repository from component scan when using Spring Data Rest
body: <p>in a spring boot project I have problems to exclude some repositories from the component scan.</p>
  
  <p>I have a library that contains some entities and some repositories (JpaRepositories). For some reason I implemented a small Spring Boot Data Rest application that shall be used to give testers a quick access to the entities. Therefore I implemented a repository that extends the PagingAndSortingRepository and is annotated with @RepositoryRestResource.</p>
  
  <p>When the application starts all repository will be scanned and made available. As long as I only want to have the Data Rest repositories available I annotated the componenten scanner to exclude the unwant repositories. But this doesn't work. I checked with the actuator beans endpoint and whatever I do - no repositories are excluded.</p>
  
  <p>To demonstrate the problem I created a simple demo application: <a href="https://github.com/magomi/springboot-restdata-repoloading" rel="noreferrer">https://github.com/magomi/springboot-restdata-repoloading</a>.</p>
  
  <p>To exclude the DataRepository I tried the two approaches:</p>
  
  <pre><code>// exclude V02
  @SpringBootApplication
  @ComponentScan(excludeFilters = {
          @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
                  DataRepository.class})
  })
  </code></pre>
  
  <p>and</p>
  
  <pre><code>// exclude V01
  @SpringBootApplication(exclude = { DataRepository.class })
  </code></pre>
  
  <p>Without success. When I call the /beans endpoint (provided by spring boot actuator) I always see</p>
  
  <pre><code>{
      bean: "dataRepository",
      aliases: [ ],
      scope: "singleton",
      type: "org.codefromhell.test.repoloading.DataRepository",
      ...
  },
  {
      bean: "dataApiRepository",
      aliases: [ ],
      scope: "singleton",
      type: "org.codefromhell.test.repoloading.api.DataApiRepository",
      ...
  },
  </code></pre>