Skip to content

Commit 88f869b

Browse files
committed
Remove misleading setters from ConfigurationPropertiesBindingPostProcessor
Previously, ConfigurationPropertiesBindingPostProcessor had a number of setter methods that implied that its configuration was more mutable than it actually is and would only have an effect when called early on in the post-processor's lifecycle. This commit clarifies how the post-processor can be configured by removing the misleading setters. Closes gh-10598
1 parent 85b1511 commit 88f869b

File tree

1 file changed

+5
-49
lines changed

1 file changed

+5
-49
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@
3535
import org.springframework.core.Ordered;
3636
import org.springframework.core.PriorityOrdered;
3737
import org.springframework.core.annotation.AnnotationUtils;
38-
import org.springframework.core.convert.ConversionService;
3938
import org.springframework.core.env.ConfigurableEnvironment;
4039
import org.springframework.core.env.Environment;
4140
import org.springframework.core.env.MutablePropertySources;
42-
import org.springframework.core.env.PropertySource;
4341
import org.springframework.core.env.PropertySources;
4442
import org.springframework.core.env.StandardEnvironment;
45-
import org.springframework.validation.Validator;
4643

4744
/**
4845
* {@link BeanPostProcessor} to bind {@link PropertySources} to beans annotated with
@@ -63,61 +60,23 @@ public class ConfigurationPropertiesBindingPostProcessor
6360

6461
private ConfigurationBeanFactoryMetaData beans = new ConfigurationBeanFactoryMetaData();
6562

66-
private Iterable<PropertySource<?>> propertySources;
67-
68-
private Validator validator;
69-
70-
private ConversionService conversionService;
71-
7263
private BeanFactory beanFactory;
7364

7465
private Environment environment = new StandardEnvironment();
7566

7667
private ApplicationContext applicationContext;
7768

78-
private int order = Ordered.HIGHEST_PRECEDENCE + 1;
79-
8069
private ConfigurationPropertiesBinder configurationPropertiesBinder;
8170

82-
/**
83-
* Set the order of the bean.
84-
* @param order the order
85-
*/
86-
public void setOrder(int order) {
87-
this.order = order;
88-
}
71+
private PropertySources propertySources;
8972

9073
/**
9174
* Return the order of the bean.
9275
* @return the order
9376
*/
9477
@Override
9578
public int getOrder() {
96-
return this.order;
97-
}
98-
99-
/**
100-
* Set the property sources to bind.
101-
* @param propertySources the property sources
102-
*/
103-
public void setPropertySources(Iterable<PropertySource<?>> propertySources) {
104-
this.propertySources = propertySources;
105-
}
106-
107-
/**
108-
* Set the bean validator used to validate property fields.
109-
* @param validator the validator
110-
*/
111-
public void setValidator(Validator validator) {
112-
this.validator = validator;
113-
}
114-
115-
/**
116-
* Set the conversion service used to convert property values.
117-
* @param conversionService the conversion service
118-
*/
119-
public void setConversionService(ConversionService conversionService) {
120-
this.conversionService = conversionService;
79+
return Ordered.HIGHEST_PRECEDENCE + 1;
12180
}
12281

12382
/**
@@ -145,9 +104,7 @@ public void setApplicationContext(ApplicationContext applicationContext) {
145104

146105
@Override
147106
public void afterPropertiesSet() throws Exception {
148-
if (this.propertySources == null) {
149-
this.propertySources = deducePropertySources();
150-
}
107+
this.propertySources = deducePropertySources();
151108
}
152109

153110
private PropertySources deducePropertySources() {
@@ -230,9 +187,8 @@ private ConfigurationProperties getAnnotation(Object bean, String beanName) {
230187
private ConfigurationPropertiesBinder getBinder() {
231188
if (this.configurationPropertiesBinder == null) {
232189
this.configurationPropertiesBinder = new ConfigurationPropertiesBinderBuilder(
233-
this.applicationContext).withConversionService(this.conversionService)
234-
.withValidator(this.validator)
235-
.withPropertySources(this.propertySources).build();
190+
this.applicationContext).withPropertySources(this.propertySources)
191+
.build();
236192
}
237193
return this.configurationPropertiesBinder;
238194
}

0 commit comments

Comments
 (0)