Merge pull request #195 from ryanjbaxter/add-bus-refresh-autoconfig
Separate refresh endpoint configuration into its own auto config
This commit is contained in:
@@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.bus.endpoint.EnvironmentBusEndpoint;
|
||||
import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint;
|
||||
import org.springframework.cloud.bus.event.AckRemoteApplicationEvent;
|
||||
import org.springframework.cloud.bus.event.EnvironmentChangeListener;
|
||||
import org.springframework.cloud.bus.event.RefreshListener;
|
||||
@@ -38,7 +37,6 @@ import org.springframework.cloud.bus.event.SentApplicationEvent;
|
||||
import org.springframework.cloud.bus.event.TraceListener;
|
||||
import org.springframework.cloud.context.environment.EnvironmentManager;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.Output;
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
@@ -176,30 +174,6 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "spring.cloud.bus.refresh.enabled", matchIfMissing = true)
|
||||
@ConditionalOnBean(ContextRefresher.class)
|
||||
public RefreshListener refreshListener(ContextRefresher contextRefresher) {
|
||||
return new RefreshListener(contextRefresher);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Endpoint.class, RefreshScope.class })
|
||||
protected static class BusRefreshConfiguration {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(ContextRefresher.class)
|
||||
protected static class BusRefreshEndpointConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnEnabledEndpoint
|
||||
public RefreshBusEndpoint refreshBusEndpoint(ApplicationContext context,
|
||||
BusProperties bus) {
|
||||
return new RefreshBusEndpoint(context, bus.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Endpoint.class })
|
||||
@ConditionalOnBean(HttpTraceRepository.class)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bus;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
||||
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.ConditionalOnProperty;
|
||||
import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint;
|
||||
import org.springframework.cloud.bus.event.RefreshListener;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnBusEnabled
|
||||
@AutoConfigureAfter(name = {"org.springframework.cloud.autoconfigure.RefreshAutoConfiguration"})
|
||||
public class BusRefreshAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "spring.cloud.bus.refresh.enabled", matchIfMissing = true)
|
||||
@ConditionalOnBean(ContextRefresher.class)
|
||||
public RefreshListener refreshListener(ContextRefresher contextRefresher) {
|
||||
return new RefreshListener(contextRefresher);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(ContextRefresher.class)
|
||||
@ConditionalOnClass(name = {"org.springframework.boot.actuate.endpoint.annotation.Endpoint",
|
||||
"org.springframework.cloud.context.scope.refresh.RefreshScope"})
|
||||
protected static class BusRefreshEndpointConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnEnabledEndpoint
|
||||
public RefreshBusEndpoint refreshBusEndpoint(ApplicationContext context,
|
||||
BusProperties bus) {
|
||||
return new RefreshBusEndpoint(context, bus.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.bus.BusPropertiesAutoConfiguration,\
|
||||
org.springframework.cloud.bus.BusAutoConfiguration,\
|
||||
org.springframework.cloud.bus.BusRefreshAutoConfiguration,\
|
||||
org.springframework.cloud.bus.jackson.BusJacksonAutoConfiguration
|
||||
|
||||
# Environment Post Processor
|
||||
|
||||
@@ -22,7 +22,7 @@ public class BusAutoConfigurationClassPathTests {
|
||||
public void refreshListenerCreatedWithoutActuator() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class,
|
||||
BusAutoConfiguration.class))
|
||||
BusRefreshAutoConfiguration.class))
|
||||
.run(context -> assertThat(context)
|
||||
.hasSingleBean(RefreshListener.class)
|
||||
.doesNotHaveBean(RefreshBusEndpoint.class));
|
||||
|
||||
Reference in New Issue
Block a user