Prevent early initialization of binding in ValidationAutoConfiguration
This commit replaces the use of ConfigurationProperties in ValidationAutoConfiguration by an explicit environment check, as it was already the case for the spring.aop.proxy-target-class property. Closes gh-45618
This commit is contained in:
@@ -221,6 +221,14 @@ class ValidationAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void validationUseDefaultAdaptToConstraintViolationsValue() {
|
||||
this.contextRunner.withUserConfiguration(AnotherSampleServiceConfiguration.class).run((context) -> {
|
||||
MethodValidationPostProcessor postProcessor = context.getBean(MethodValidationPostProcessor.class);
|
||||
assertThat(postProcessor).hasFieldOrPropertyWithValue("adaptConstraintViolations", false);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void userDefinedMethodValidationPostProcessorTakesPrecedence() {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.validation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ValidationProperties}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class ValidationPropertiesTests {
|
||||
|
||||
@Test
|
||||
void adaptConstraintViolationsPropertyDefaultMatchesPostProcessorDefault() {
|
||||
assertThat(new MethodValidationPostProcessor()).extracting("adaptConstraintViolations")
|
||||
.isEqualTo(new ValidationProperties().getMethod().isAdaptConstraintViolations());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user