Polish "Add spring.validation.method.adapt-constraint-violations property"
See gh-43886
This commit is contained in:
parent
0e7d480545
commit
c20f6cba8a
|
@ -71,14 +71,13 @@ public class ValidationAutoConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
|
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
|
||||||
public static MethodValidationPostProcessor methodValidationPostProcessor(Environment environment,
|
public static MethodValidationPostProcessor methodValidationPostProcessor(Environment environment,
|
||||||
ObjectProvider<Validator> validator, ObjectProvider<MethodValidationExcludeFilter> excludeFilters,
|
ValidationProperties validationProperties, ObjectProvider<Validator> validator,
|
||||||
ObjectProvider<ValidationProperties> validationProperties) {
|
ObjectProvider<MethodValidationExcludeFilter> excludeFilters) {
|
||||||
FilteredMethodValidationPostProcessor processor = new FilteredMethodValidationPostProcessor(
|
FilteredMethodValidationPostProcessor processor = new FilteredMethodValidationPostProcessor(
|
||||||
excludeFilters.orderedStream());
|
excludeFilters.orderedStream());
|
||||||
boolean proxyTargetClass = environment.getProperty("spring.aop.proxy-target-class", Boolean.class, true);
|
boolean proxyTargetClass = environment.getProperty("spring.aop.proxy-target-class", Boolean.class, true);
|
||||||
processor.setProxyTargetClass(proxyTargetClass);
|
processor.setProxyTargetClass(proxyTargetClass);
|
||||||
processor
|
processor.setAdaptConstraintViolations(validationProperties.getMethod().isAdaptConstraintViolations());
|
||||||
.setAdaptConstraintViolations(validationProperties.getObject().getMethod().isAdaptConstraintViolations());
|
|
||||||
processor.setValidatorProvider(validator);
|
processor.setValidatorProvider(validator);
|
||||||
return processor;
|
return processor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,18 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.validation;
|
package org.springframework.boot.autoconfigure.validation;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Role;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration properties for validation.
|
* {@link ConfigurationProperties @ConfigurationProperties} for validation.
|
||||||
*
|
*
|
||||||
* @author Yanming Zhou
|
* @author Yanming Zhou
|
||||||
|
* @author Andy Wilkinson
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||||
@ConfigurationProperties(prefix = "spring.validation")
|
@ConfigurationProperties(prefix = "spring.validation")
|
||||||
public class ValidationProperties {
|
public class ValidationProperties {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue