DATACMNS-989 - Use exclude filters when scanning for custom repository implementations.

The detection algorithm for custom repository implementations now considers the exclude filters declared in the overall repository setup (XML and annotations).

Original pull request: #195.
This commit is contained in:
Peter Rietzler
2017-02-10 09:11:26 +01:00
committed by Oliver Gierke
parent f8715ac8a8
commit 3ca77831e1
12 changed files with 59 additions and 8 deletions

View File

@@ -18,6 +18,6 @@ package org.springframework.data.repository.config;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSourceUnitTests.Person;
interface MyOtherRepository extends Repository<Person, Long> {
interface MyOtherRepository extends Repository<Person, Long>, MyOtherRepositoryExtensions {
}

View File

@@ -0,0 +1,5 @@
package org.springframework.data.repository.config;
public interface MyOtherRepositoryExtensions {
String getImplementationId();
}

View File

@@ -0,0 +1,8 @@
package org.springframework.data.repository.config;
public class MyOtherRepositoryImpl implements MyOtherRepositoryExtensions {
@Override
public String getImplementationId() {
return getClass().getName();
}
}

View File

@@ -23,18 +23,21 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupportUnitTests.DummyConfigurationExtension;
/**
* Integration tests for {@link RepositoryBeanDefinitionRegistrarSupport}.
*
* @author Oliver Gierke
* @author Peter Rietzler
*/
public class RepositoryBeanDefinitionRegistrarSupportIntegrationTests {
@Configuration
@EnableRepositories
@EnableRepositories(excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*\\.excluded\\..*"))
static class SampleConfig {
}
@@ -59,6 +62,11 @@ public class RepositoryBeanDefinitionRegistrarSupportIntegrationTests {
}
}
@Test // DATACMNS-989
public void duplicateImplementationsMayBeExcludedViaFilters() {
assertThat(context.getBean(MyOtherRepository.class).getImplementationId(), is(MyOtherRepositoryImpl.class.getName()));
}
@Test // DATACMNS-47
public void testBootstrappingWithInheritedConfigClasses() {

View File

@@ -0,0 +1,10 @@
package org.springframework.data.repository.config.excluded;
import org.springframework.data.repository.config.MyOtherRepositoryExtensions;
public class MyOtherRepositoryImpl implements MyOtherRepositoryExtensions {
@Override
public String getImplementationId() {
return getClass().getName();
}
}