[英]Spring boot validate form
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. 我正在按照本教程来验证表单,但是由于我使用的是Spring Boot,因此我想避免使用mvc-dispatcher-servlet.xml文件。
So instead of inserting it in the project I wrote a bean in my @Configuration class, obtaining this message: 因此,与其在项目中插入它,不如在我的@Configuration类中编写了一个bean,获得了以下消息:
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?
我做错了什么?
您可以将OrderValidator指定为实现org.springframework.validation.Validator
的@Component
,以便可以找到并注入Validator实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.