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:
@@ -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;
|
||||||
import org.springframework.cloud.context.config.BeanLifecycleDecorator.Context;
|
import org.springframework.cloud.context.config.BeanLifecycleDecorator.Context;
|
||||||
import org.springframework.cloud.context.config.StandardBeanLifecycleDecorator;
|
import org.springframework.cloud.context.config.StandardBeanLifecycleDecorator;
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.expression.BeanFactoryAccessor;
|
import org.springframework.context.expression.BeanFactoryAccessor;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
import org.springframework.expression.ParseException;
|
import org.springframework.expression.ParseException;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.util.StringValueResolver;
|
import org.springframework.util.StringValueResolver;
|
||||||
|
|
||||||
@@ -336,27 +333,6 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor, Disposable
|
|||||||
this.scoped = scoped;
|
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
|
@Override
|
||||||
protected Object resolveValue(Object value) {
|
protected Object resolveValue(Object value) {
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|||||||
import org.springframework.cloud.context.scope.refresh.ImportRefreshScopeIntegrationTests.TestConfiguration;
|
import org.springframework.cloud.context.scope.refresh.ImportRefreshScopeIntegrationTests.TestConfiguration;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@SpringApplicationConfiguration(classes = TestConfiguration.class)
|
@SpringApplicationConfiguration(classes = TestConfiguration.class)
|
||||||
@@ -46,7 +45,6 @@ public class ImportRefreshScopeIntegrationTests {
|
|||||||
private org.springframework.cloud.context.scope.refresh.RefreshScope scope;
|
private org.springframework.cloud.context.scope.refresh.RefreshScope scope;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
|
||||||
public void testSimpleProperties() throws Exception {
|
public void testSimpleProperties() throws Exception {
|
||||||
assertEquals("Hello scope!", service.getMessage());
|
assertEquals("Hello scope!", service.getMessage());
|
||||||
assertEquals("refresh", beanFactory.getBeanDefinition("service").getScope());
|
assertEquals("refresh", beanFactory.getBeanDefinition("service").getScope());
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
|
|||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.cloud.context.environment.EnvironmentManager;
|
import org.springframework.cloud.context.environment.EnvironmentManager;
|
||||||
import org.springframework.cloud.context.scope.refresh.RefreshScopeConfigurationTests.NestedApp.NestedController;
|
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.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -42,7 +41,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
*/
|
*/
|
||||||
public class RefreshScopeConfigurationTests {
|
public class RefreshScopeConfigurationTests {
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException expected = ExpectedException.none();
|
public ExpectedException expected = ExpectedException.none();
|
||||||
@@ -65,10 +64,16 @@ public class RefreshScopeConfigurationTests {
|
|||||||
* See gh-43
|
* See gh-43
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore("gh-43")
|
||||||
public void configurationWithRefreshScope() throws Exception {
|
public void configurationWithRefreshScope() throws Exception {
|
||||||
expected.expectMessage("Scoped proxies not allowed on @Configuration");
|
|
||||||
context = new AnnotationConfigApplicationContext(Application.class,
|
context = new AnnotationConfigApplicationContext(Application.class,
|
||||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.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
|
@Test
|
||||||
@@ -83,7 +88,6 @@ public class RefreshScopeConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("SPR-12486")
|
|
||||||
public void refreshScopeOnNested() throws Exception {
|
public void refreshScopeOnNested() throws Exception {
|
||||||
context = new AnnotationConfigApplicationContext(NestedApp.class,
|
context = new AnnotationConfigApplicationContext(NestedApp.class,
|
||||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class);
|
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class);
|
||||||
@@ -118,7 +122,7 @@ public class RefreshScopeConfigurationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration("application")
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
protected static class Application {
|
protected static class Application {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user