From 2caf87f92e5830074df86d9a85d183f684e7dcfd Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 3 Dec 2014 17:19:05 +0000 Subject: [PATCH] Revert some @Ignores after bugfixes in Spring Also lifts the restriction on @RefreshScope and @Configuration (since that was imposed by a bug). Fixes gh-43 --- docs/src/main/asciidoc/spring-cloud-config.adoc | 9 +++++++++ .../refresh/ImportRefreshScopeIntegrationTests.java | 4 +--- .../scope/refresh/RefreshScopeConfigurationTests.java | 5 ++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index d633b4af..2be3046b 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -291,6 +291,15 @@ target cache. There is also a `refresh(String)` method to refresh an individual bean by name. This functionality is exposed in the `/refresh` endpoint (over HTTP or JMX). +NOTE: `@RefreshScope` works (technically) on an `@Configuration` +class, but it might lead to surprising behaviour: e.g. it does *not* +mean that all the `@Beans` defined in that class are themselves +`@RefreshScope`. Specifically, anything that depends on those beans +cannot rely on them being updated when a refresh is initiated, unless +it is itself in `@RefreshScope` (in which it will be rebuilt on a +refresh and its dependencies re-injected, at which point they will be +re-initialized from the refreshed `@Configuration`). + === Encryption and Decryption The Config Client has an `Environment` pre-processor for decrypting diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java index fbceb601..76cb9a74 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java @@ -17,7 +17,6 @@ package org.springframework.cloud.context.scope.refresh; import static org.junit.Assert.assertEquals; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +31,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @SpringApplicationConfiguration(classes = TestConfiguration.class) @RunWith(SpringJUnit4ClassRunner.class) -@Ignore("gh-43") public class ImportRefreshScopeIntegrationTests { @Autowired @@ -47,7 +45,7 @@ public class ImportRefreshScopeIntegrationTests { @Test public void testSimpleProperties() throws Exception { assertEquals("Hello scope!", service.getMessage()); - assertEquals("refresh", beanFactory.getBeanDefinition("service").getScope()); + assertEquals("refresh", beanFactory.getBeanDefinition("scopedTarget.service").getScope()); assertEquals("Hello scope!", service.getMessage()); } diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java index 24185e6d..b94f6cbc 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java @@ -18,7 +18,6 @@ package org.springframework.cloud.context.scope.refresh; import static org.junit.Assert.assertEquals; import org.junit.After; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -64,12 +63,11 @@ public class RefreshScopeConfigurationTests { * See gh-43 */ @Test - @Ignore("gh-43") public void configurationWithRefreshScope() throws Exception { context = new AnnotationConfigApplicationContext(Application.class, PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class); Application application = context.getBean(Application.class); - assertEquals("refresh", context.getBeanDefinition("application").getScope()); + assertEquals("refresh", context.getBeanDefinition("scopedTarget.application").getScope()); application.hello(); refresh(); String message = application.hello(); @@ -126,6 +124,7 @@ public class RefreshScopeConfigurationTests { @RefreshScope protected static class Application { + @Value("${message:Hello World!}") String message = "Hello World"; @RequestMapping("/")