diff --git a/spring-cloud-context/pom.xml b/spring-cloud-context/pom.xml
index 80007b24..fa74e07c 100644
--- a/spring-cloud-context/pom.xml
+++ b/spring-cloud-context/pom.xml
@@ -53,6 +53,16 @@
spring-boot-starter-test
test
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+ test
+
+
+ org.hsqldb
+ hsqldb
+ test
+
org.springframework.cloud
spring-cloud-commons
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 4315a129..d0fa13bc 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
@@ -33,6 +33,7 @@ import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.framework.Advised;
+import org.springframework.aop.scope.ScopedObject;
import org.springframework.aop.scope.ScopedProxyFactoryBean;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
@@ -457,7 +458,8 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor,
Method method = invocation.getMethod();
if (AopUtils.isEqualsMethod(method)
|| AopUtils.isToStringMethod(method)
- || AopUtils.isHashCodeMethod(method)) {
+ || AopUtils.isHashCodeMethod(method)
+ || isScopedObjectGetTargetObject(method)) {
return invocation.proceed();
}
Object proxy = getObject();
@@ -477,6 +479,12 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor,
lock.unlock();
}
}
+
+ private boolean isScopedObjectGetTargetObject(Method method) {
+ return method.getDeclaringClass().equals(ScopedObject.class)
+ && method.getName().equals("getTargetObject")
+ && method.getParameterTypes().length == 0;
+ }
}
}
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 e48b33a0..aecbb80c 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
@@ -25,23 +25,24 @@ import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
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.autoconfigure.RefreshAutoConfiguration;
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;
import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
+import javax.sql.DataSource;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
@@ -198,8 +199,7 @@ public class RefreshScopeIntegrationTests {
@Configuration
@EnableConfigurationProperties(TestProperties.class)
- @Import({ RefreshAutoConfiguration.class,
- PropertyPlaceholderAutoConfiguration.class })
+ @EnableAutoConfiguration
protected static class TestConfiguration {
@Autowired
@@ -214,6 +214,11 @@ public class RefreshScopeIntegrationTests {
return service;
}
+ @Bean
+ @RefreshScope
+ public DataSource dataSource(DataSourceProperties dataSourceProperties) {
+ return dataSourceProperties.initializeDataSourceBuilder().build();
+ }
}
@ConfigurationProperties
diff --git a/spring-cloud-context/src/test/resources/application.properties b/spring-cloud-context/src/test/resources/application.properties
index d6aa5969..0a72683d 100644
--- a/spring-cloud-context/src/test/resources/application.properties
+++ b/spring-cloud-context/src/test/resources/application.properties
@@ -3,4 +3,5 @@ delay: 0
debug: true
#logging.level.org.springframework.web: DEBUG
#logging.level.org.springframework.context.annotation: DEBUG
+logging.level.org.hibernate=ERROR
management.security.enabled=false