in a spring boot project I have problems to exclude some repositories from the component scan.
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.
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.
To demonstrate the problem I created a simple demo application: https://github.com/magomi/springboot-restdata-repoloading.
To exclude the DataRepository I tried the two approaches:
// exclude V02
@SpringBootApplication
@ComponentScan(excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
DataRepository.class})
})
and
// exclude V01
@SpringBootApplication(exclude = { DataRepository.class })
Without success. When I call the /beans endpoint (provided by spring boot actuator) I always see
{
bean: "dataRepository",
aliases: [ ],
scope: "singleton",
type: "org.codefromhell.test.repoloading.DataRepository",
...
},
{
bean: "dataApiRepository",
aliases: [ ],
scope: "singleton",
type: "org.codefromhell.test.repoloading.api.DataApiRepository",
...
},