Add a AddValueExtractorsLocalValidatorFactoryBean that expand LocalValidatorFactoryBean which based SpringFramework, it can support user add custom ValueExtractor(s). For example, user can define ValueExtractor like this in their application:

@Component
public class CustomValueExtractor implements ValueExtractor<CustomResult<@ExtractedValue ?>> {

     @Override
     public void extractValues(CustomResult<?> result, ValueReceiver valueReceiver) {
         valueReceiver.value(null, result.getData());
     }
}

And modify the class ValidationAutoConfiguration, auto-configure an instance of type AddValueExtractorsLocalValidatorFactoryBean instead of type LocalValidatorFactoryBean

Comment From: wilkinsona

Thanks for the proposal, @dangzhicairang. Do you think it's likely that you will want to inject dependencies into a customValueExtractor implementation? If so, there would be a benefit to them being beans, but if not it may be better to provide a more general callback for customizing the validator Configuration.

Comment From: dangzhicairang

Thanks for the proposal, @dangzhicairang. Do you think it's likely that you will want to inject dependencies into a customValueExtractor implementation? If so, there would be a benefit to them being beans, but if not it may be better to provide a more general callback for customizing the validator Configuration.

Thank you @wilkinsona , it is a really nice suggestion, and i provide a callback class Customizer for the Configuration. And i retained the ability to automatically add the ValueExtractor(s) bean, so user can choose whether these ValueExtractor(s) are bean or not. The ValueExtractor which is bean will automatically add but added by Customizer or AddValueExtractorCustomizer if it not.

Comment From: wilkinsona

Thanks for the updates, @dangzhicairang. Our feeling is that the general-purpose callback mechanism possibly belongs in Spring Framework rather than in Spring Boot, particularly as Framework already has its own LocalValidatorFactoryBean sub-class. I've raised https://github.com/spring-projects/spring-framework/issues/27956 so that the Framework team can consider things. I'll place this proposal on hold until we know what, if anything, the Framework team are going to do.

Comment From: dangzhicairang

Thanks for the updates, @dangzhicairang. Our feeling is that the general-purpose callback mechanism possibly belongs in Spring Framework rather than in Spring Boot, particularly as Framework already has its own LocalValidatorFactoryBean sub-class. I've raised spring-projects/spring-framework#27956 so that the Framework team can consider things. I'll place this proposal on hold until we know what, if anything, the Framework team are going to do.

Thank you for your reply @wilkinsona . It is right.

Comment From: snicoll

https://github.com/spring-projects/spring-framework/issues/27956 has been addressed.

Comment From: wilkinsona

Thanks very much for making your first contribution to Spring Boot, @dangzhicairang.

I have updated your proposal a little in https://github.com/spring-projects/spring-boot/commit/0e00fafe385256d5da1e5a26fd8fd97173ba8d32 to make use of the changes to Framework's LocalValidatorFactoryBean. In the interests of simplicity, I've removed support for ValueExtractor beans, preferring a more general callback mechanism that can be used to customise the configuration as needed, including adding value extractors.

Comment From: dangzhicairang

Thanks very much for making your first contribution to Spring Boot, @dangzhicairang.

I have updated your proposal a little in 0e00faf to make use of the changes to Framework's LocalValidatorFactoryBean. In the interests of simplicity, I've removed support for ValueExtractor beans, preferring a more general callback mechanism that can be used to customise the configuration as needed, including adding value extractors.

Thanks a lot for your update @wilkinsona