Closed pluttrell closed 7 years ago
Duplicates #8495
What bugs me in the example is that you're mentioning JSR 303 Validator (javax.validation.Validator
) and that's not what you're injecting. On the other hand the Data Rest contract does not seem to allow you to pass such object. That actually makes the case for #8495 :(
When using the following Gradle dependencies:
If you want to enable universal JSR 303 Bean Validations on Spring Data Rest as shown here, with this class:
You'll get the following error on startup:
The cause appears to be that there are multiple
Validator
beans defined. If I look atorg/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration
I see the following method within:Shouldn't the
@ConditionalOnMissingBean
annotation mean that this bean doesn't get created given that there is already another one namedmvcValidator
created?Annotating the injection
@Lazy
does not resolve the issue as noted here.Annotating the injection either
@Qualifier("jsr303Validator")
or@Qualifier("mvcValidator")
does resolve the problem. But which one should we use?