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
This commit is contained in:
parent
59a906bd58
commit
76c4819053
|
|
@ -106,15 +106,6 @@ public class ConfigurationPropertiesBinder {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this binder instance.
|
||||
*/
|
||||
void destroy() {
|
||||
if (this.validator instanceof InternalValidator) {
|
||||
((InternalValidator) this.validator).destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private Validator determineValidator(Object bean) {
|
||||
boolean supportsBean = (this.validator != null
|
||||
&& this.validator.supports(bean.getClass()));
|
||||
|
|
@ -154,16 +145,6 @@ public class ConfigurationPropertiesBinder {
|
|||
return details.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Validator} extension to be implemented to signal that that validator can be
|
||||
* destroyed once the binder is no longer in use.
|
||||
*/
|
||||
interface InternalValidator extends Validator {
|
||||
|
||||
void destroy();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Validator} implementation that wraps {@link Validator} instances and chains
|
||||
* their execution.
|
||||
|
|
|
|||
|
|
@ -25,15 +25,12 @@ import org.springframework.beans.BeansException;
|
|||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.PriorityOrdered;
|
||||
|
|
@ -58,7 +55,7 @@ import org.springframework.validation.Validator;
|
|||
*/
|
||||
public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProcessor,
|
||||
BeanFactoryAware, EnvironmentAware, ApplicationContextAware, InitializingBean,
|
||||
DisposableBean, ApplicationListener<ContextRefreshedEvent>, PriorityOrdered {
|
||||
PriorityOrdered {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(ConfigurationPropertiesBindingPostProcessor.class);
|
||||
|
|
@ -152,23 +149,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
freeBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
freeBinder();
|
||||
}
|
||||
|
||||
private void freeBinder() {
|
||||
if (this.configurationPropertiesBinder != null) {
|
||||
this.configurationPropertiesBinder.destroy();
|
||||
}
|
||||
this.configurationPropertiesBinder = null;
|
||||
}
|
||||
|
||||
private PropertySources deducePropertySources() {
|
||||
PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer();
|
||||
if (configurer != null) {
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
|||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean
|
||||
implements ConfigurationPropertiesBinder.InternalValidator {
|
||||
class ValidatedLocalValidatorFactoryBean extends LocalValidatorFactoryBean {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(ConfigurationPropertiesBindingPostProcessor.class);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import javax.validation.constraints.NotNull;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.boot.context.properties.bind.validation.BindValidationException;
|
||||
import org.springframework.boot.context.properties.bind.validation.ValidationErrors;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
|
|
@ -39,8 +38,6 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConfigurationPropertiesBinderBuilder}.
|
||||
|
|
@ -140,19 +137,6 @@ public class ConfigurationPropertiesBinderBuilderTests {
|
|||
assertThat(target.getBar()).isEqualTo("654321");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void internalValidatorIsClosed() throws Exception {
|
||||
ConfigurationPropertiesBinder binder = this.builder
|
||||
.withEnvironment(this.environment).build();
|
||||
Object validator = ReflectionTestUtils.getField(binder, "validator");
|
||||
assertThat(validator).isNotNull();
|
||||
assertThat(validator).isInstanceOf(DisposableBean.class);
|
||||
DisposableBean validatorSpy = spy((DisposableBean) validator);
|
||||
ReflectionTestUtils.setField(binder, "validator", validatorSpy);
|
||||
binder.destroy();
|
||||
verify(validatorSpy).destroy();
|
||||
}
|
||||
|
||||
private ValidationErrors bindWithValidationErrors(
|
||||
ConfigurationPropertiesBinder binder, Object target) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ import org.springframework.core.env.SystemEnvironmentPropertySource;
|
|||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.test.context.support.TestPropertySourceUtils;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
|
@ -87,17 +86,6 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void binderIsNullOutAfterContextRefresh() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
ConfigurationPropertiesBindingPostProcessor bean = this.context
|
||||
.getBean(ConfigurationPropertiesBindingPostProcessor.class);
|
||||
assertThat(ReflectionTestUtils.getField(bean, "configurationPropertiesBinder"))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindToInterfaceBean() {
|
||||
MockEnvironment env = new MockEnvironment();
|
||||
|
|
|
|||
Loading…
Reference in New Issue