spring3 mvc @Valid annotation cannot be found

拜拜、爱过 提交于 2020-05-31 06:56:20

问题


I try to use @Valid annotation, but eclipse always gives the "Valid cannot be resolved to a type" error. I m using the spring3 library.

I have imported hibernate-validator-4.1.0.Final.jar into my WEB-INF/lib directory. however, this does not solve the problem.

Any help is appreciated!


回答1:


As far as I remember the @Valid annotation is part of the validation-api JAR which you can find in the lib directory of the Hibernate Validator, as you have already downloaded the Hibernate implementation. The @Valid is a part of the javax.validation annotation API. You can add this JAR to your class path to be able to properly reference the annotation.




回答2:


@Valid belongs to JSR-303. You can get it via maven using this dependency:

<dependency>
  <groupId>javax.validation</groupId>
  <artifactId>validation-api</artifactId>
  <version>1.0.0.GA</version>
</dependency>

Or you can download it from this page.



来源:https://stackoverflow.com/questions/4098697/spring3-mvc-valid-annotation-cannot-be-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!