DATACMNS-494 - Removed the defaulting of the environment in RepositoryBeanDefinitionRegistrarSupport.
As SPR-11744 got fixed recently and will be available in Spring 3.2.9, we removed the guard in RepositoryBeanDefinitionRegistrarSupport which defaulted the environment in case it was not set by the container. Related tickets: SPR-11744.
This commit is contained in:
@@ -23,8 +23,6 @@ import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.EnvironmentCapable;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -73,9 +71,6 @@ public abstract class RepositoryBeanDefinitionRegistrarSupport implements Import
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: remove once SPR-11744 gets fixed
|
||||
Environment environment = defaultEnvironment(this.environment, resourceLoader);
|
||||
|
||||
AnnotationRepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(
|
||||
annotationMetadata, getAnnotation(), resourceLoader, environment);
|
||||
|
||||
@@ -84,23 +79,6 @@ public abstract class RepositoryBeanDefinitionRegistrarSupport implements Import
|
||||
delegate.registerRepositoriesIn(registry, getExtension());
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults the environment in case the given one is null. TODO: remove, once SPR-11744 gets fixed.
|
||||
*
|
||||
* @param environment
|
||||
* @param resourceLoader
|
||||
* @return
|
||||
*/
|
||||
private static Environment defaultEnvironment(Environment environment, ResourceLoader resourceLoader) {
|
||||
|
||||
if (environment != null) {
|
||||
return environment;
|
||||
}
|
||||
|
||||
return resourceLoader instanceof EnvironmentCapable ? ((EnvironmentCapable) resourceLoader).getEnvironment()
|
||||
: new StandardEnvironment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the annotation to obtain configuration information from. Will be wrappen into an
|
||||
* {@link AnnotationRepositoryConfigurationSource} so have a look at the constants in there for what annotation
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -34,7 +35,7 @@ import org.springframework.data.repository.core.support.RepositoryFactoryBeanSup
|
||||
|
||||
/**
|
||||
* Integration test for {@link RepositoryBeanDefinitionRegistrarSupport}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -42,11 +43,23 @@ public class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
|
||||
@Mock BeanDefinitionRegistry registry;
|
||||
|
||||
StandardEnvironment environment;
|
||||
DummyRegistrar registrar;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
environment = new StandardEnvironment();
|
||||
|
||||
registrar = new DummyRegistrar();
|
||||
registrar.setEnvironment(environment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registersBeanDefinitionForFoundBean() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
|
||||
DummyRegistrar registrar = new DummyRegistrar();
|
||||
|
||||
registrar.registerBeanDefinitions(metadata, registry);
|
||||
|
||||
assertBeanDefinitionRegisteredFor("myRepository");
|
||||
@@ -60,8 +73,6 @@ public class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
public void registeredProfileRepositoriesIfProfileActivated() {
|
||||
|
||||
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
|
||||
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
environment.setActiveProfiles("profile");
|
||||
|
||||
DummyRegistrar registrar = new DummyRegistrar();
|
||||
|
||||
Reference in New Issue
Block a user