Browse Source

Migrate from deprecate methods (#610)

Migrate away from deprecated Spring Boot configuration property
bean classes and methods.
pull/616/head
Phil Webb 5 years ago committed by Spencer Gibb
parent
commit
2ded4eb554
  1. 12
      spring-cloud-context/src/main/java/org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.java
  2. 33
      spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesBeans.java

12
spring-cloud-context/src/main/java/org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.java

@ -20,7 +20,6 @@ import org.springframework.beans.factory.SmartInitializingSingleton; @@ -20,7 +20,6 @@ import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans;
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
@ -49,16 +48,7 @@ public class ConfigurationPropertiesRebinderAutoConfiguration @@ -49,16 +48,7 @@ public class ConfigurationPropertiesRebinderAutoConfiguration
@Bean
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
public ConfigurationPropertiesBeans configurationPropertiesBeans() {
// Since this is a BeanPostProcessor we have to be super careful not to
// cause a cascade of bean instantiation. Knowing the *name* of the beans we
// need is super optimal, but a little brittle (unfortunately we have no
// choice).
ConfigurationBeanFactoryMetadata metaData = this.context.getBean(
ConfigurationBeanFactoryMetadata.BEAN_NAME,
ConfigurationBeanFactoryMetadata.class);
ConfigurationPropertiesBeans beans = new ConfigurationPropertiesBeans();
beans.setBeanMetaDataStore(metaData);
return beans;
return new ConfigurationPropertiesBeans();
}
@Bean

33
spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesBeans.java

@ -24,11 +24,9 @@ import java.util.Set; @@ -24,11 +24,9 @@ import java.util.Set;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
/**
@ -36,15 +34,14 @@ import org.springframework.stereotype.Component; @@ -36,15 +34,14 @@ import org.springframework.stereotype.Component;
* its parent.
*
* @author Dave Syer
*
*/
@Component
public class ConfigurationPropertiesBeans
implements BeanPostProcessor, ApplicationContextAware {
private ConfigurationBeanFactoryMetadata metaData;
private Map<String, ConfigurationPropertiesBean> beans = new HashMap<>();
private Map<String, Object> beans = new HashMap<String, Object>();
private ApplicationContext applicationContext;
private ConfigurableListableBeanFactory beanFactory;
@ -57,6 +54,7 @@ public class ConfigurationPropertiesBeans @@ -57,6 +54,7 @@ public class ConfigurationPropertiesBeans
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
if (applicationContext
.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory) {
this.beanFactory = (ConfigurableListableBeanFactory) applicationContext
@ -77,9 +75,13 @@ public class ConfigurationPropertiesBeans @@ -77,9 +75,13 @@ public class ConfigurationPropertiesBeans
/**
* @param beans The bean meta data to set.
* @deprecated since 2.2.0 because
* {@link org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata}
* has been deprecated
*/
public void setBeanMetaDataStore(ConfigurationBeanFactoryMetadata beans) {
this.metaData = beans;
@Deprecated
public void setBeanMetaDataStore(
org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata beans) {
}
@Override
@ -88,17 +90,10 @@ public class ConfigurationPropertiesBeans @@ -88,17 +90,10 @@ public class ConfigurationPropertiesBeans
if (isRefreshScoped(beanName)) {
return bean;
}
ConfigurationProperties annotation = AnnotationUtils
.findAnnotation(bean.getClass(), ConfigurationProperties.class);
if (annotation != null) {
this.beans.put(beanName, bean);
}
else if (this.metaData != null) {
annotation = this.metaData.findFactoryAnnotation(beanName,
ConfigurationProperties.class);
if (annotation != null) {
this.beans.put(beanName, bean);
}
ConfigurationPropertiesBean propertiesBean = ConfigurationPropertiesBean
.get(this.applicationContext, bean, beanName);
if (propertiesBean != null) {
this.beans.put(beanName, propertiesBean);
}
return bean;
}

Loading…
Cancel
Save