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
@Valid annotation - This annotation disallowed for this location
提问by Kevin Rave
I have controller method that has @Valid
annotation to enforce JSR303 Bean validation.
我有一个带有@Valid
注释的控制器方法来强制执行 JSR303 Bean 验证。
But when I just give @Valid
is 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 @Valid
validation 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.Valid
when you just use @Valid
.
看看你的进口。我猜您javax.validation.Valid
只是使用@Valid
.
回答by parvinder09
You need to import below packages for @Valid
and @Size
to 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