Breaking changes in ValidationAutoConfiguration.defaultValidator() between Spring Boot 2.5 and 2.6 should be mentioned in the 2.6 Release notes at https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes.
2.5: https://github.com/spring-projects/spring-boot/blob/6c4781086fc2fec77b0994e09e4a561d8739b616/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.java#L58
2.6: https://github.com/spring-projects/spring-boot/blob/f8c9fee3b0c8ff9ef48cf12fb4a9f8a51630a485/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.java#L59
Comment From: wilkinsona
As described in the documentation, we don't consider this to be a breaking change:
Even though auto-configuration classes are public, the only aspect of the class that is considered public API is the name of the class which can be used for disabling the auto-configuration. The actual contents of those classes, such as nested configuration classes or bean methods are for internal use only and we do not recommend using those directly.
Please note that we intend to enforce this at some point in the future.
With that said, it would still be interesting to learn why you were calling the defaultValidator method on ValidationAutoConfiguration. Calling auto-configuration class methods can be an indication that either there's a better way that you could be doing something that's already available or that we need to provide a better way of doing something.
Comment From: brsolomon-deloitte
Thanks for the docs link @wilkinsona; we can close this issue.
With that said, it would still be interesting to learn why you were calling the defaultValidator method on ValidationAutoConfiguration.
Here's the existing usage (where I've added applicationContext to at least get the build un-broken).
public class AddressValidatorTests {
@Autowired
private ApplicationContext applicationContext;
private final Validator validator = new DelegatingValidator(
Collections.singletonList(new AddressValidator()),
ValidationAutoConfiguration.defaultValidator(applicationContext)); // JSR-303 Validation Annotations
@Test
public void testUnitedStatesAddressWhenMissingState() {
BindingResult result = ValidationHelper.validate(validator, addressDTOBuilder()
.country(UNITED_STATES_OF_AMERICA)
.address1("12345 Street")
.city("ABC")
.zip("12345")
.build());
Where ValidationHelper looks like:
public class ValidationHelper {
public static BindingResult validate(Validator validator, Object dto) {
...
Comment From: wilkinsona
Assuming the use of JUnit 5, you should be able to do something like this instead:
public class AddressValidatorTests {
private final Validator validator;
AddressValidatorTests(@Autowired LocalValidatorFactoryBean defaultValidator) {
this.validator = new DelegatingValidator(Collections.singletonList(new AddressValidator()), defaultValidator);
}
// …
}