Moves declaration of EnvironmentManager
fixes gh-314
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.cloud.context.environment.EnvironmentManager;
|
||||
@@ -31,6 +32,7 @@ import org.springframework.cloud.endpoint.GenericPostableMvcEndpoint;
|
||||
import org.springframework.cloud.endpoint.RefreshEndpoint;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
/**
|
||||
* Autoconfiguration for some MVC endpoints governing the application context lifecycle.
|
||||
@@ -41,42 +43,52 @@ import org.springframework.context.annotation.Configuration;
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(EnvironmentEndpoint.class)
|
||||
@ConditionalOnWebApplication
|
||||
@AutoConfigureAfter({ WebMvcAutoConfiguration.class,
|
||||
RefreshEndpointAutoConfiguration.class })
|
||||
public class LifecycleMvcEndpointAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(EnvironmentEndpoint.class)
|
||||
@ConditionalOnEnabledEndpoint(value = "env.post")
|
||||
public EnvironmentManagerMvcEndpoint environmentManagerEndpoint(
|
||||
EnvironmentEndpoint delegate, EnvironmentManager environment) {
|
||||
return new EnvironmentManagerMvcEndpoint(delegate, environment);
|
||||
@ConditionalOnMissingBean
|
||||
public EnvironmentManager environmentManager(ConfigurableEnvironment environment) {
|
||||
return new EnvironmentManager(environment);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(RefreshEndpoint.class)
|
||||
public MvcEndpoint refreshMvcEndpoint(RefreshEndpoint endpoint) {
|
||||
return new GenericPostableMvcEndpoint(endpoint);
|
||||
}
|
||||
@Configuration
|
||||
@ConditionalOnClass(EnvironmentEndpoint.class)
|
||||
@ConditionalOnWebApplication
|
||||
protected static class EndpointConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(RestartEndpoint.class)
|
||||
public RestartMvcEndpoint restartMvcEndpoint(RestartEndpoint restartEndpoint) {
|
||||
return new RestartMvcEndpoint(restartEndpoint);
|
||||
}
|
||||
@Bean
|
||||
@ConditionalOnBean(EnvironmentEndpoint.class)
|
||||
@ConditionalOnEnabledEndpoint(value = "env.post")
|
||||
public EnvironmentManagerMvcEndpoint environmentManagerMvcEndpoint(
|
||||
EnvironmentEndpoint delegate, EnvironmentManager environment) {
|
||||
return new EnvironmentManagerMvcEndpoint(delegate, environment);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(RestartEndpoint.PauseEndpoint.class)
|
||||
public MvcEndpoint pauseMvcEndpoint(RestartEndpoint.PauseEndpoint pauseEndpoint) {
|
||||
return new GenericPostableMvcEndpoint(pauseEndpoint);
|
||||
}
|
||||
@Bean
|
||||
@ConditionalOnBean(RefreshEndpoint.class)
|
||||
public MvcEndpoint refreshMvcEndpoint(RefreshEndpoint endpoint) {
|
||||
return new GenericPostableMvcEndpoint(endpoint);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(RestartEndpoint.ResumeEndpoint.class)
|
||||
public MvcEndpoint resumeMvcEndpoint(RestartEndpoint.ResumeEndpoint resumeEndpoint) {
|
||||
return new GenericPostableMvcEndpoint(resumeEndpoint);
|
||||
@Bean
|
||||
@ConditionalOnBean(RestartEndpoint.class)
|
||||
public RestartMvcEndpoint restartMvcEndpoint(RestartEndpoint restartEndpoint) {
|
||||
return new RestartMvcEndpoint(restartEndpoint);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(RestartEndpoint.PauseEndpoint.class)
|
||||
public MvcEndpoint pauseMvcEndpoint(RestartEndpoint.PauseEndpoint pauseEndpoint) {
|
||||
return new GenericPostableMvcEndpoint(pauseEndpoint);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(RestartEndpoint.ResumeEndpoint.class)
|
||||
public MvcEndpoint resumeMvcEndpoint(RestartEndpoint.ResumeEndpoint resumeEndpoint) {
|
||||
return new GenericPostableMvcEndpoint(resumeEndpoint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -78,12 +78,6 @@ public class RefreshAutoConfiguration {
|
||||
return new LoggingRebinder();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public EnvironmentManager environmentManager(ConfigurableEnvironment environment) {
|
||||
return new EnvironmentManager(environment);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ContextRefresher contextRefresher(ConfigurableApplicationContext context,
|
||||
|
||||
@@ -37,7 +37,7 @@ public class LifecycleMvcAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void postEnvMvcEndpointEnabled() {
|
||||
beanCreated("environmentManagerEndpoint",
|
||||
beanCreated("environmentManagerMvcEndpoint",
|
||||
"endpoints.env.post.enabled=true");
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class RefreshAutoConfigurationTests {
|
||||
@Test
|
||||
public void noWarnings() {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(
|
||||
Config.class)) {
|
||||
false, Config.class)) {
|
||||
assertThat(context.containsBean("refreshScope")).isTrue();
|
||||
assertThat(output.toString()).doesNotContain("WARN");
|
||||
}
|
||||
@@ -32,14 +32,14 @@ public class RefreshAutoConfigurationTests {
|
||||
@Test
|
||||
public void disabled() {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(
|
||||
Config.class, "spring.cloud.refresh.enabled:false")) {
|
||||
true, Config.class, "spring.cloud.refresh.enabled:false")) {
|
||||
assertThat(context.containsBean("refreshScope")).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext getApplicationContext(
|
||||
Class<?> configuration, String... properties) {
|
||||
return new SpringApplicationBuilder(configuration).web(false).properties(properties).run();
|
||||
boolean web, Class<?> configuration, String... properties) {
|
||||
return new SpringApplicationBuilder(configuration).web(web).properties(properties).run();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.LifecycleMvcEndpointAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.cloud.context.environment.EnvironmentManager;
|
||||
@@ -65,7 +66,7 @@ public class RefreshScopeConfigurationTests {
|
||||
@Test
|
||||
public void configurationWithRefreshScope() throws Exception {
|
||||
context = new AnnotationConfigApplicationContext(Application.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class);
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class, LifecycleMvcEndpointAutoConfiguration.class);
|
||||
Application application = context.getBean(Application.class);
|
||||
assertEquals("refresh", context.getBeanDefinition("scopedTarget.application").getScope());
|
||||
application.hello();
|
||||
@@ -77,7 +78,7 @@ public class RefreshScopeConfigurationTests {
|
||||
@Test
|
||||
public void refreshScopeOnBean() throws Exception {
|
||||
context = new AnnotationConfigApplicationContext(ClientApp.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class);
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class, LifecycleMvcEndpointAutoConfiguration.class);
|
||||
Controller application = context.getBean(Controller.class);
|
||||
application.hello();
|
||||
refresh();
|
||||
@@ -88,7 +89,7 @@ public class RefreshScopeConfigurationTests {
|
||||
@Test
|
||||
public void refreshScopeOnNested() throws Exception {
|
||||
context = new AnnotationConfigApplicationContext(NestedApp.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class);
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class, LifecycleMvcEndpointAutoConfiguration.class);
|
||||
NestedController application = context.getBean(NestedController.class);
|
||||
application.hello();
|
||||
refresh();
|
||||
|
||||
Reference in New Issue
Block a user