java 找不到 spring3 mvc @Valid 注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4098697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 04:45:36  来源:igfitidea点击:

spring3 mvc @Valid annotation cannot be found

javaspringhibernate-validator

提问by EeE

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.

我尝试使用@Valid 注释,但 eclipse 总是给出“Valid 无法解析为类型”错误。我正在使用 spring3 库。

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

我已将 hibernate-validator-4.1.0.Final.jar 导入到我的 WEB-INF/lib 目录中。然而,这并不能解决问题。

Any help is appreciated!

任何帮助表示赞赏!

回答by Sean Patrick Floyd

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

@Valid属于JSR-303。您可以使用此依赖项通过 Maven 获取它:

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

Or you can download it from this page.

或者你可以从这个页面下载它。

回答by Niall Thomson

As far as I remember the @Validannotation 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 @Validis 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.

据我所知,@Valid注释是验证 API JAR 的一部分,您可以在 Hibernate Validator 的 lib 目录中找到它,因为您已经下载了 Hibernate 实现。这@Valid是 javax.validation 注释 API 的一部分。您可以将此 JAR 添加到您的类路径中,以便能够正确引用注释。