Revert some of the changes to RefreshScope and @Configuration

Some things were changed in Spring and some problems are fixed
(while at least one is not - scope!="refresh" for a @Configuration
with @RefreshScope)
This commit is contained in:
Dave Syer
2014-12-03 14:31:39 +00:00
parent 001e449be2
commit 0d2cb07384
3 changed files with 9 additions and 31 deletions

View File

@@ -38,16 +38,13 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.cloud.context.config.BeanLifecycleDecorator;
import org.springframework.cloud.context.config.BeanLifecycleDecorator.Context;
import org.springframework.cloud.context.config.StandardBeanLifecycleDecorator;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.expression.BeanFactoryAccessor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.ParseException;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.StringValueResolver;
@@ -336,27 +333,6 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor, Disposable
this.scoped = scoped;
}
@Override
protected void visitBeanClassName(BeanDefinition beanDefinition) {
String className = beanDefinition.getBeanClassName();
if (className!=null) {
Class<?> type = ClassUtils.resolveClassName(className, null);
Assert.state(
!beanDefinition.getScope().equals(scope)
|| AnnotationUtils.findAnnotation(type,
Configuration.class) == null,
"Scoped proxies not allowed on @Configuration (for '" + scope
+ "' scope) on bean of type " + type);
org.springframework.context.annotation.Scope beanScope = AnnotationUtils
.findAnnotation(type,
org.springframework.context.annotation.Scope.class);
if (beanScope != null && !scoped && beanScope.value().equals(scope)) {
beanDefinition.setScope(scope);
}
}
super.visitBeanClassName(beanDefinition);
}
@Override
protected Object resolveValue(Object value) {

View File

@@ -28,7 +28,6 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.scope.refresh.ImportRefreshScopeIntegrationTests.TestConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@SpringApplicationConfiguration(classes = TestConfiguration.class)
@@ -46,7 +45,6 @@ public class ImportRefreshScopeIntegrationTests {
private org.springframework.cloud.context.scope.refresh.RefreshScope scope;
@Test
@DirtiesContext
public void testSimpleProperties() throws Exception {
assertEquals("Hello scope!", service.getMessage());
assertEquals("refresh", beanFactory.getBeanDefinition("service").getScope());

View File

@@ -29,7 +29,6 @@ import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.environment.EnvironmentManager;
import org.springframework.cloud.context.scope.refresh.RefreshScopeConfigurationTests.NestedApp.NestedController;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -42,7 +41,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
public class RefreshScopeConfigurationTests {
private ConfigurableApplicationContext context;
private AnnotationConfigApplicationContext context;
@Rule
public ExpectedException expected = ExpectedException.none();
@@ -65,10 +64,16 @@ public class RefreshScopeConfigurationTests {
* See gh-43
*/
@Test
@Ignore("gh-43")
public void configurationWithRefreshScope() throws Exception {
expected.expectMessage("Scoped proxies not allowed on @Configuration");
context = new AnnotationConfigApplicationContext(Application.class,
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class);
Application application = context.getBean(Application.class);
assertEquals("refresh", context.getBeanDefinition("application").getScope());
application.hello();
refresh();
String message = application.hello();
assertEquals("Hello Dave!", message);
}
@Test
@@ -83,7 +88,6 @@ public class RefreshScopeConfigurationTests {
}
@Test
@Ignore("SPR-12486")
public void refreshScopeOnNested() throws Exception {
context = new AnnotationConfigApplicationContext(NestedApp.class,
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class);
@@ -118,7 +122,7 @@ public class RefreshScopeConfigurationTests {
}
@Configuration
@Configuration("application")
@RefreshScope
protected static class Application {