Hibernate - 注释验证

时间:2017-10-22 13:11:04

标签: hibernate validation exception-handling

在我的spring mvc + hibernate web app中,我在控制台上收到以下消息 当我尝试验证我的表格时

13:05:41.225 [http-nio-8080-exec-4] DEBUG org.springframework.web.cors.DefaultCorsProcessor - Skip CORS processing: request is from same origin
13:05:41.377 [http-nio-8080-exec-4] DEBUG org.springframework.core.annotation.AnnotationUtils - Failed to meta-introspect annotation [class com.sun.proxy.$Proxy57]: java.lang.NoSuchMethodException: javax.validation.Valid.value()
13:05:41.631 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.notempty.NotEmptyValidatorForCharSequence'
13:05:41.653 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
13:05:41.654 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.notempty.NotEmptyValidatorForCharSequence'
13:05:41.671 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.size.SizeValidatorForCharSequence'
13:05:41.702 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
13:05:41.703 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.size.SizeValidatorForCharSequence'
13:05:41.704 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.notempty.NotEmptyValidatorForCharSequence'
13:05:41.704 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.notempty.NotEmptyValidatorForCharSequence'
13:05:41.705 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.size.SizeValidatorForCharSequence'
13:05:41.705 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.size.SizeValidatorForCharSequence'
13:05:41.705 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.NotNullValidator'
13:05:41.719 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
13:05:41.720 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.NotNullValidator'
13:05:41.720 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator'
13:05:41.772 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
13:05:41.776 [http-nio-8080-exec-4] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator'

用户表单:

protected Long id;

protected String registrationNumber;

@NotNull
protected Civility civility;

@NotEmpty
@Size(min = 3)
private String firstName;

@NotEmpty
@Size(min = 3)
protected String lastName;

@Email
protected String email;

UserController中

@PostMapping(path = "/submit/{id}", headers = "X-Requested-With=XMLHttpRequest")
public @ResponseBody JsonResponse submit(@PathVariable Long id, @Valid SelfForm self, BindingResult result, Model model) {

    if (!result.hasErrors()) {
    .........
    }else{
    ...........
    }
    ..........
}

我应如何在控制台中摆脱这条线

DEBUG org.springframework.core.annotation.AnnotationUtils - 无法进行meta-introspect注释[class com.sun.proxy。$ Proxy57]:java.lang.NoSuchMethodException:javax.validation.Valid.value()

0 个答案:

没有答案