DATACMNS-542 - Be more lenient about simplified way to customize repository base classes.

We now leniently return null for the repository base class name from the AnnotationRepositoryConfigurationSource to make sure Spring Data modules compile against Spring Data Commons 1.10 continue to work on 1.11 without having the annotation attribute added.
This commit is contained in:
Oliver Gierke
2015-07-13 17:39:49 +02:00
parent 1dbd3941f1
commit cd6b2c09c6
2 changed files with 30 additions and 0 deletions

View File

@@ -221,6 +221,10 @@ public class AnnotationRepositoryConfigurationSource extends RepositoryConfigura
@Override
public String getRepositoryBaseClassName() {
if (!attributes.containsKey(REPOSITORY_BASE_CLASS)) {
return null;
}
Class<? extends Object> repositoryBaseClass = attributes.getClass(REPOSITORY_BASE_CLASS);
return DefaultRepositoryBaseClass.class.equals(repositoryBaseClass) ? null : repositoryBaseClass.getName();
}

View File

@@ -18,6 +18,8 @@ package org.springframework.data.repository.config;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collection;
import org.junit.Before;
@@ -146,6 +148,19 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
assertThat(getConfigSource(DefaultConfiguration.class).usesExplicitFilters(), is(false));
}
/**
* @see DATACMNS-542
*/
@Test
public void ignoresMissingRepositoryBaseClassNameAttribute() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(ConfigWithSampleAnnotation.class, true);
RepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata,
SampleAnnotation.class, resourceLoader, environment);
assertThat(configurationSource.getRepositoryBaseClassName(), is(nullValue()));
}
private AnnotationRepositoryConfigurationSource getConfigSource(Class<?> type) {
AnnotationMetadata metadata = new StandardAnnotationMetadata(type, true);
@@ -165,4 +180,15 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
@EnableRepositories(excludeFilters = { @Filter(Primary.class) })
static class ConfigurationWithExplicitFilter {}
@Retention(RetentionPolicy.RUNTIME)
@interface SampleAnnotation {
Filter[] includeFilters() default {};
Filter[] excludeFilters() default {};
}
@SampleAnnotation
static class ConfigWithSampleAnnotation {}
}