When trying to autowire a ConstraintValidator with a service, it doesn't get injected when used by Hibernate. See sample application here:

https://github.com/gamov/spring-validator-autowired-issue

Comment From: snicoll

@gamov thanks for the sample but I am not sure I understand what you expected? The constraint validator is created by Hibernate, not Spring so it won't be turned magically into a bean.

If you have more questions, please ask on StackOverflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

Comment From: mohamedmahmoudkashif

@gamov thanks for the sample but I am not sure I understand what you expected? The constraint validator is created by Hibernate, not Spring so it won't be turned magically into a bean.

If you have more questions, please ask on StackOverflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

You could answer him if you have a solution or any direction he could use instead asking hin=m to go to stackoverflow, what is the wrong with you guys!!!!!

Comment From: wilkinsona

@mohamedelkashif The support provided in the issue track is free and it is unreasonable to demand that the Spring Boot team and community spend their time in a way that suits you. We do our best to help users, however, to keep the issue tracker manageable both for the core team and everyone watching the repository, we prefer that questions are asked on Stack Overflow and Gitter.

In this case, @snicoll has already taken the time to point out that the ConstraintValidator isn't available for dependency injection as it's created by Hibernate and, therefore, isn't a Spring-managed bean. If that wasn't enough of a direction to solve the problem, a question on Stack Overflow is a better place to continue.

If you require more formal support with guaranteed responses then that is available but you will have to pay for it.

Comment From: gamov

Hello. That's an old issue, I'm not sure I remember correctly but we just followed the instructions provided here: https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#validation-beanvalidation-spring-constraints and we didn't observe the expected behaviour.

But nvm. Thanks for your time.

Comment From: MnsrIl

Hello. Using jakarta, Spring Boot 3. Was following instruction from the documentation https://docs.spring.io/spring-framework/reference/core/validation/beanvalidation.html#validation-beanvalidation-spring-constraints, but in reality my injected beans are null and therefore I am not able to use them in my custom constraint validator. Is there a way to fix this issue/maybe it's the known one and fix is on the way?

By the post above, I see, that this error is kinda of really old and I'm curious is this going to be fixed or will it just vanish from the documentation? Because now I'm expecting that everything should work just fine, but unfortunately, I'm not even able to get expected result from the documentation.

Thanks for your time.

Comment From: wilkinsona

@MnsrIl The documentation that you have linked to is part of Spring Framework which is managed as a separate project. If you believe that it is not behaving as documented, please open a Spring Framework issue and provide a minimal sample that shows that the documented behavior is not working.

Comment From: MnsrIl

@wilkinsona to be clear, do I right understand, that the functionality I'm talking about should've been fixed in spring framework, not in spring boot? Because I was thinking, that it should've been autoconfigured in boot project, not in the framework itself.

Is there a chance that the problem occurres due to old version of some dependency used in boot?

Comment From: wilkinsona

Spring Boot will auto-configure a LocalValidatorFactoryBean that largely uses Spring Framework's defaults:

https://github.com/spring-projects/spring-boot/blob/2ef31951f86c56a27873b281b21d2ffde9759d0c/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.java#L55-L66

Among those defaults, is the ConstraintValidatorFactory which will be a SpringConstraintValidatorFactory that allows ConstraintValidator implementations to be Spring beans. I can't say much more beyond this as you haven't told us much about your application. A question on Stack Overflow may be the best option at this point.