-
Notifications
You must be signed in to change notification settings - Fork 38k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document autowiring of javax.validation.Validator with use of @EnableWebMvc [SPR-12194] #16808
Comments
Andy Wilkinson commented Pull request: spring-attic/spring-framework-issues#85 |
Andy Wilkinson commented Some further information that I shared with Rossen on HipChat:
|
Gunnar Hillert commented Not sure how related this issue is. I noticed an I have a custom Validator in PersistenceConfig.class
In WebConfig.class which extends WebMvcConfigurerAdapter and uses
However, getValidator() never gets executed. Code fails with:
If I declare:
Inside WebConfig.class, everything works. |
Chris Beams commented Hey guys, I'm getting bit by this bug as well in the following environment:
Any attempt to directly I do have a workaround, though it is unpleasant: @Controller
class MyController {
private final BeanFactory beanFactory;
private Validator validator;
@Autowired
public MyController(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@InitBinder
protected void initBinder() {
// work around #16808
this.validator = beanFactory.getBean(Validator.class);
}
// ...
} |
Matt Byrne commented Just to give another scenario of where this fails ... I've encountered the same problem using spring boot 1.2.3.RELEASE and hibernate validator 5.2.0.Beta1, however I'm also using a Collections validator library to validate collections of Strings, Integers https://github.com/jirutka/validator-collection which autowires in a In some of my own classes I need to autowire the To get around the problem I had to avoid configuring my own Not nice, but the only way I could get around this before it's fixed. |
Rossen Stoyanchev commented The An application can make things more explicit either by "overriding" the mvcValidator bean (and declaring it as LocalValidatorFactoryBean) or by declaring a separate LocalValidatorFactoryBean and marking it |
Matt Byrne commented Thanks Rossen, I had already tried overriding the mvcValidator definition in my Config class and tried declaring it as If this is the final solution it would be worth adding some instructions to the doco since it seemed to get us by surprise. |
Rossen Stoyanchev commented See 6890e6. |
Andy Wilkinson opened SPR-12194 and commented
I'm seeing some strange behaviour with
@EnableWebMvc
and autowiring ofjavax.validation.Validator
.When there's no explicitly-configured
LocalValidatorFactoryBean
, auto-wiring ofjavax.validation.Validator
fails as no matching bean is found. When there's a single explicitly-configuredLocalValidatorFactoryBean
, auto-wiring fails as there are now two matching beans: the explicitly configured one and the one that's provided by@EnableWebMvc
.I'll open a Spring Framework Issues PR with some code to reproduce both behaviours.
Affects: 4.0.7, 4.1 GA
Reference URL: spring-projects/spring-boot#1539
3 votes, 9 watchers
The text was updated successfully, but these errors were encountered: