Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRuud Claassen
9,359 PointsCould not autowire. There is more than one bean of 'Validator' type
Wanted to autowire the Validator validator, as done in the video (4:20). Reviewed the other questions, but none covers this specific case. I now receive a curly red line underneath the validator variable, with the following message on hover:
Beans: Could not autowire. There is more than one bean of 'Validator' type
defaultValidator (ValidationAutoConfiguration.class)
mvcValidator (WebMvcAutoConfiguration.class)
Code does run however...
Thanks!
1 Answer
Brice Roberts
22,415 PointsChange
@Autowired
private Validator validator;
@Override
public void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener validatingListener) {
validatingListener.addValidator("beforeCreate", validator);
validatingListener.addValidator("beforeSave", validator);
}
to
@Bean
public Validator validator() {
return new LocalValidatorFactoryBean();
}
@Override
public void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener validatingListener) {
validatingListener.addValidator("beforeCreate", validator());
validatingListener.addValidator("beforeSave", validator());
}
More info
johnhunter
12,964 Pointsjohnhunter
12,964 PointsHad the same issue. Brice's solution worked for me. Thanks! ??