0

I'm following this tutorial in order to validate my form, but since I'm using spring boot I wanted to avoid the mvc-dispatcher-servlet.xml file.

So instead of inserting it in the project I wrote a bean in my @Configuration class, obtaining this message:

Field validator in my.package.controller.MyController required a bean of type 'org.springframework.validation.Validator' that could not be found.
- Bean method 'resourceServerProperties' not loaded because @ConditionalOnClass did not find required class 'org.springframework.security.oauth2.common.OAuth2AccessToken'

I have tried both those beans:

    @Bean
public Validator validator() {      
    return new org.springframework.validation.beanvalidation.LocalValidatorFactoryBean();
}    

@Bean
public javax.validation.Validator localValidatorFactoryBean() {
   return new LocalValidatorFactoryBean();
}

with the same result. What I'm doing wrong?

1
  • 2
    Remove those beans. You are stating you are using Spring Boot which already configures that bean. You don't need to inject anything you only need @Valid on the method argument you want to validate. Commented Dec 12, 2016 at 19:16

1 Answer 1

2

You could specify the OrderValidator as a @Component which implements org.springframework.validation.Validator, so the Validator implementation can be found and injected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.