Skip to content

Commit 76c4819

Browse files
committed
Remove internal configuration properties validator cleanup
This commit removes the cleanup of the javax.validator.Validator that can be created to validate @ConfigurationProperties binding as the memory effect can no longer be reproduced. Closes gh-10573
1 parent 59a906b commit 76c4819

File tree

5 files changed

+2
-70
lines changed

5 files changed

+2
-70
lines changed

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,6 @@ void bind(Object target, ConfigurationProperties annotation) {
106106
}
107107
}
108108

109-
/**
110-
* Destroy this binder instance.
111-
*/
112-
void destroy() {
113-
if (this.validator instanceof InternalValidator) {
114-
((InternalValidator) this.validator).destroy();
115-
}
116-
}
117-
118109
private Validator determineValidator(Object bean) {
119110
boolean supportsBean = (this.validator != null
120111
&& this.validator.supports(bean.getClass()));
@@ -154,16 +145,6 @@ private String getAnnotationDetails(ConfigurationProperties annotation) {
154145
return details.toString();
155146
}
156147

157-
/**
158-
* {@link Validator} extension to be implemented to signal that that validator can be
159-
* destroyed once the binder is no longer in use.
160-
*/
161-
interface InternalValidator extends Validator {
162-
163-
void destroy();
164-
165-
}
166-
167148
/**
168149
* {@link Validator} implementation that wraps {@link Validator} instances and chains
169150
* their execution.

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@
2525
import org.springframework.beans.factory.BeanCreationException;
2626
import org.springframework.beans.factory.BeanFactory;
2727
import org.springframework.beans.factory.BeanFactoryAware;
28-
import org.springframework.beans.factory.DisposableBean;
2928
import org.springframework.beans.factory.InitializingBean;
3029
import org.springframework.beans.factory.ListableBeanFactory;
3130
import org.springframework.beans.factory.config.BeanPostProcessor;
3231
import org.springframework.context.ApplicationContext;
3332
import org.springframework.context.ApplicationContextAware;
34-
import org.springframework.context.ApplicationListener;
3533
import org.springframework.context.EnvironmentAware;
36-
import org.springframework.context.event.ContextRefreshedEvent;
3734
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
3835
import org.springframework.core.Ordered;
3936
import org.springframework.core.PriorityOrdered;
@@ -58,7 +55,7 @@
5855
*/
5956
public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProcessor,
6057
BeanFactoryAware, EnvironmentAware, ApplicationContextAware, InitializingBean,
61-
DisposableBean, ApplicationListener<ContextRefreshedEvent>, PriorityOrdered {
58+
PriorityOrdered {
6259

6360
private static final Log logger = LogFactory
6461
.getLog(ConfigurationPropertiesBindingPostProcessor.class);
@@ -152,23 +149,6 @@ public void afterPropertiesSet() throws Exception {
152149
}
153150
}
154151

155-
@Override
156-
public void onApplicationEvent(ContextRefreshedEvent event) {
157-
freeBinder();
158-
}
159-
160-
@Override
161-
public void destroy() {
162-
freeBinder();
163-
}
164-
165-
private void freeBinder() {
166-
if (this.configurationPropertiesBinder != null) {
167-
this.configurationPropertiesBinder.destroy();
168-
}
169-
this.configurationPropertiesBinder = null;
170-
}
171-
172152
private PropertySources deducePropertySources() {
173153
PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer();
174154
if (configurer != null) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
*
3232
* @author Phillip Webb
3333
*/
34-
class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean
35-
implements ConfigurationPropertiesBinder.InternalValidator {
34+
class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean {
3635

3736
private static final Log logger = LogFactory
3837
.getLog(ConfigurationPropertiesBindingPostProcessor.class);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinderBuilderTests.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import org.junit.Test;
2424

25-
import org.springframework.beans.factory.DisposableBean;
2625
import org.springframework.boot.context.properties.bind.validation.BindValidationException;
2726
import org.springframework.boot.context.properties.bind.validation.ValidationErrors;
2827
import org.springframework.context.support.StaticApplicationContext;
@@ -39,8 +38,6 @@
3938
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
4039

4140
import static org.assertj.core.api.Assertions.assertThat;
42-
import static org.mockito.Mockito.spy;
43-
import static org.mockito.Mockito.verify;
4441

4542
/**
4643
* Tests for {@link ConfigurationPropertiesBinderBuilder}.
@@ -140,19 +137,6 @@ public void validationWithJsr303AndValidInput() {
140137
assertThat(target.getBar()).isEqualTo("654321");
141138
}
142139

143-
@Test
144-
public void internalValidatorIsClosed() throws Exception {
145-
ConfigurationPropertiesBinder binder = this.builder
146-
.withEnvironment(this.environment).build();
147-
Object validator = ReflectionTestUtils.getField(binder, "validator");
148-
assertThat(validator).isNotNull();
149-
assertThat(validator).isInstanceOf(DisposableBean.class);
150-
DisposableBean validatorSpy = spy((DisposableBean) validator);
151-
ReflectionTestUtils.setField(binder, "validator", validatorSpy);
152-
binder.destroy();
153-
verify(validatorSpy).destroy();
154-
}
155-
156140
private ValidationErrors bindWithValidationErrors(
157141
ConfigurationPropertiesBinder binder, Object target) {
158142
try {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.springframework.lang.Nullable;
5656
import org.springframework.mock.env.MockEnvironment;
5757
import org.springframework.test.context.support.TestPropertySourceUtils;
58-
import org.springframework.test.util.ReflectionTestUtils;
5958
import org.springframework.util.StringUtils;
6059
import org.springframework.validation.annotation.Validated;
6160

@@ -87,17 +86,6 @@ public void close() {
8786
}
8887
}
8988

90-
@Test
91-
public void binderIsNullOutAfterContextRefresh() {
92-
this.context = new AnnotationConfigApplicationContext();
93-
this.context.register(TestConfiguration.class);
94-
this.context.refresh();
95-
ConfigurationPropertiesBindingPostProcessor bean = this.context
96-
.getBean(ConfigurationPropertiesBindingPostProcessor.class);
97-
assertThat(ReflectionTestUtils.getField(bean, "configurationPropertiesBinder"))
98-
.isNull();
99-
}
100-
10189
@Test
10290
public void bindToInterfaceBean() {
10391
MockEnvironment env = new MockEnvironment();

0 commit comments

Comments
 (0)