diff --git a/spring-cloud-context-integration-tests/src/test/java/org/springframework/cloud/context/integration/RefreshScopeIntegrationTests.java b/spring-cloud-context-integration-tests/src/test/java/org/springframework/cloud/context/integration/RefreshScopeIntegrationTests.java index e9b808bc..098db40a 100644 --- a/spring-cloud-context-integration-tests/src/test/java/org/springframework/cloud/context/integration/RefreshScopeIntegrationTests.java +++ b/spring-cloud-context-integration-tests/src/test/java/org/springframework/cloud/context/integration/RefreshScopeIntegrationTests.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.aop.framework.Advised; +import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +34,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.integration.RefreshScopeIntegrationTests.TestConfiguration; -import org.springframework.cloud.context.scope.GenericScope; import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -117,7 +117,7 @@ public class RefreshScopeIntegrationTests { then(ExampleService.getDestroyCount()).isEqualTo(1); then(id2).isNotSameAs(id1); then(ExampleService.event).isNotNull(); - then(ExampleService.event.getName()).isEqualTo(GenericScope.SCOPED_TARGET_PREFIX + "service"); + then(ExampleService.event.getName()).isEqualTo(ScopedProxyUtils.getTargetBeanName("service")); } // see gh-349 diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java index 17485bb0..5ac36134 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java @@ -73,11 +73,6 @@ import org.springframework.util.StringUtils; public class GenericScope implements Scope, BeanFactoryPostProcessor, BeanDefinitionRegistryPostProcessor, DisposableBean { - /** - * Prefix for the scoped target. - */ - public static final String SCOPED_TARGET_PREFIX = "scopedTarget."; - private static final Log logger = LogFactory.getLog(GenericScope.class); private BeanLifecycleWrapperCache cache = new BeanLifecycleWrapperCache(new StandardScopeCache()); diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/refresh/RefreshScope.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/refresh/RefreshScope.java index 42c4b451..44018606 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/refresh/RefreshScope.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/refresh/RefreshScope.java @@ -18,6 +18,7 @@ package org.springframework.cloud.context.scope.refresh; import java.io.Serializable; +import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -132,10 +133,10 @@ public class RefreshScope extends GenericScope @ManagedOperation(description = "Dispose of the current instance of bean name " + "provided and force a refresh on next method execution.") public boolean refresh(String name) { - if (!name.startsWith(SCOPED_TARGET_PREFIX)) { + if (!ScopedProxyUtils.isScopedTarget(name)) { // User wants to refresh the bean with this name but that isn't the one in the // cache... - name = SCOPED_TARGET_PREFIX + name; + name = ScopedProxyUtils.getTargetBeanName(name); } // Ensure lifecycle is finished if bean was disposable if (super.destroy(name)) { diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java index 3b07a3e8..18b75bfa 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java @@ -19,6 +19,7 @@ package org.springframework.cloud.context.scope.refresh; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.test.context.SpringBootTest; @@ -47,7 +48,8 @@ public class ImportRefreshScopeIntegrationTests { @Test public void testSimpleProperties() throws Exception { then(this.service.getMessage()).isEqualTo("Hello scope!"); - then(this.beanFactory.getBeanDefinition("scopedTarget.service").getScope()).isEqualTo("refresh"); + then(this.beanFactory.getBeanDefinition(ScopedProxyUtils.getTargetBeanName("service")).getScope()) + .isEqualTo("refresh"); then(this.service.getMessage()).isEqualTo("Hello scope!"); } diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java index 8214d58c..709e6c78 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java @@ -21,6 +21,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; @@ -72,7 +73,8 @@ public class RefreshScopeConfigurationTests { PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class, LifecycleMvcEndpointAutoConfiguration.class); Application application = this.context.getBean(Application.class); - then(this.context.getBeanDefinition("scopedTarget.application").getScope()).isEqualTo("refresh"); + then(this.context.getBeanDefinition(ScopedProxyUtils.getTargetBeanName("application")).getScope()) + .isEqualTo("refresh"); application.hello(); refresh(); String message = application.hello(); diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeIntegrationTests.java index 4f24354a..46209dbc 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeIntegrationTests.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.aop.framework.Advised; +import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +33,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.cloud.context.scope.GenericScope; import org.springframework.cloud.context.scope.refresh.RefreshScopeIntegrationTests.TestConfiguration; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -115,7 +115,7 @@ public class RefreshScopeIntegrationTests { then(ExampleService.getDestroyCount()).isEqualTo(1); then(id2).isNotSameAs(id1); then(ExampleService.event).isNotNull(); - then(ExampleService.event.getName()).isEqualTo(GenericScope.SCOPED_TARGET_PREFIX + "service"); + then(ExampleService.event.getName()).isEqualTo(ScopedProxyUtils.getTargetBeanName("service")); } // see gh-349 diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeLazyIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeLazyIntegrationTests.java index 669b0927..c1186183 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeLazyIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeLazyIntegrationTests.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.aop.framework.Advised; +import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +35,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration; import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.cloud.context.scope.GenericScope; import org.springframework.cloud.context.scope.refresh.RefreshScopeLazyIntegrationTests.TestConfiguration; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -117,7 +117,7 @@ public class RefreshScopeLazyIntegrationTests { then(ExampleService.getDestroyCount()).isEqualTo(1); then(id2).isNotSameAs(id1); then(ExampleService.event).isNotNull(); - then(ExampleService.event.getName()).isEqualTo(GenericScope.SCOPED_TARGET_PREFIX + "service"); + then(ExampleService.event.getName()).isEqualTo(ScopedProxyUtils.getTargetBeanName("service")); } public interface Service { diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeWebIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeWebIntegrationTests.java index ff4e45a0..ee62fd3f 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeWebIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeWebIntegrationTests.java @@ -19,6 +19,7 @@ package org.springframework.cloud.context.scope.refresh; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -58,7 +59,8 @@ public class RefreshScopeWebIntegrationTests { @Test public void scopeOnBeanDefinition() throws Exception { - then(this.beanFactory.getBeanDefinition("scopedTarget.application").getScope()).isEqualTo("refresh"); + then(this.beanFactory.getBeanDefinition(ScopedProxyUtils.getTargetBeanName("application")).getScope()) + .isEqualTo("refresh"); } @Test