Register a BeanDefinition manually instead of using @Bean
For RefreshScope this stops Spring from moaning about the @Bean method with a WARN log (which is benign but hard to get rid of and confusing for users). See gh-401
This commit is contained in:
@@ -17,6 +17,12 @@
|
||||
|
||||
package org.springframework.cloud.autoconfigure;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
@@ -29,6 +35,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Autoconfiguration for the refresh scope and associated features to do with changes in
|
||||
@@ -42,10 +49,24 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
||||
public class RefreshAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public static RefreshScope refreshScope() {
|
||||
return new RefreshScope();
|
||||
@Component
|
||||
@ConditionalOnMissingBean(RefreshScope.class)
|
||||
protected static class RefreshScopeConfiguration
|
||||
implements BeanDefinitionRegistryPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
||||
throws BeansException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
|
||||
throws BeansException {
|
||||
registry.registerBeanDefinition("refreshScope",
|
||||
BeanDefinitionBuilder.genericBeanDefinition(RefreshScope.class)
|
||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
.getBeanDefinition());
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user