DATACMNS-492 - RepositoryConfigurationDelegate now expects an Environment.

Added a constructor to RepositoryConfigurationDelegate that takes an additional Environment instance to make sure we can equip ClasspathScanningCandidateComponentProviders with Environments to make sure they only find components matching the environment.

Retain the old constructor by defaulting to the Environment the ResourceLoader potentially contains or even a StandardEnvironment in worse cases. This is primarily to not break existing clients. Those should be upgraded to use the new constructor, of course.

Needed to add an additional guard in BeanDefinitionRegistrarSupport as Spring 3.2.8 fails to invoke EnvironmentAware (filed SPR-11744 for that). This should be removed once we upgrade to Spring 3.2.9.

Related pull request: #80.
Related tickets: DATACMNS-493, DATACMNS-494, SPR-11744.
This commit is contained in:
Oliver Gierke
2014-04-29 08:01:07 +02:00
parent 63e595b0af
commit ec49499e50
6 changed files with 107 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,12 +18,16 @@ package org.springframework.data.repository.config;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.After;
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.Configuration;
/**
* Integration tests for {@link RepositoryBeanDefinitionRegistrarSupport}.
*
* @author Oliver Gierke
*/
public class RepositoryBeanDefinitionRegistrarSupportIntegrationTests {
@@ -39,20 +43,37 @@ public class RepositoryBeanDefinitionRegistrarSupportIntegrationTests {
}
AnnotationConfigApplicationContext context;
@Before
public void setUp() {
this.context = new AnnotationConfigApplicationContext(TestConfig.class);
}
@After
public void tearDown() {
if (context != null) {
this.context.close();
}
}
/**
* @see DATACMNS-47
*/
@Test
public void testBootstrappingWithInheritedConfigClasses() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
assertThat(context.getBean(MyRepository.class), is(notNullValue()));
assertThat(context.getBean(MyOtherRepository.class), is(notNullValue()));
}
/**
* @see DATACMNS-47
*/
@Test
public void beanDefinitionSourceIsSetForJavaConfigScannedBeans() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
BeanDefinition definition = context.getBeanDefinition("myRepository");
assertThat(definition.getSource(), is(notNullValue()));
}