Java @Valid 注释 - 此位置不允许使用此注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16284353/
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-08-16 06:10:09  来源:igfitidea点击:

@Valid annotation - This annotation disallowed for this location

javaspring-mvcannotationsbean-validation

提问by Kevin Rave

I have controller method that has @Validannotation to enforce JSR303 Bean validation.

我有一个带有@Valid注释的控制器方法来强制执行 JSR303 Bean 验证。

But when I just give @Validis shows"

但当我只是给的@Valid是表演”

This annotation @Valid is disallowed for this location

I can get rid of this by giving full package path @javax.validation.Valid. It does not show the above message if I use this.

我可以通过提供完整的包路径来摆脱这个@javax.validation.Valid。如果我使用它,它不会显示上述消息。

My question is, would there be any conflict that is forcing me to give full package name? Or some jars missing?

我的问题是,是否有任何冲突迫使我提供完整的包名称?还是缺少一些罐子?

I wouldn't be asking this question, if @Validvalidation is working fine. But its not working either, though there is no compile or run time error. It is just not triggering.

如果@Valid验证工作正常,我不会问这个问题。但它也不起作用,尽管没有编译或运行时错误。它只是没有触发。

I posted this issue herein a different thread.

我张贴了这个问题,这里在不同的线程。

采纳答案by a better oliver

Take a look at your imports. I guess you are not importing javax.validation.Validwhen you just use @Valid.

看看你的进口。我猜您javax.validation.Valid只是使用@Valid.

回答by parvinder09

You need to import below packages for @Validand @Sizeto work:

您需要导入以下包@Valid@Size工作:

import javax.validation.Valid;
import javax.validation.constraints.Size;

And the necessary jars which are required to work this are given below:

下面给出了执行此操作所需的必要 jars:

  • classmate-1.0.0.jar
  • hibernate-validator-5.1.3.Final.jar
  • javax.el-2.2.4.jar
  • javax.el-api-2.2.4.jar
  • jboss-logging-3.1.3.GA.jar
  • validation-api-1.1.0.Final.ja
  • 同学-1.0.0.jar
  • hibernate-validator-5.1.3.Final.jar
  • javax.el-2.2.4.jar
  • javax.el-api-2.2.4.jar
  • jboss-logging-3.1.3.GA.jar
  • 验证api-1.1.0.Final.ja

You can download above jars from http://hibernate.org/validator/

您可以从http://hibernate.org/validator/下载以上 jars