Java Spring引导-从2.2.5升级到2.3.0后验证停止工作
我已经将SpringBoot项目从2.2.5迁移到2.3.0,之后,验证停止工作(根本不调用它们) 我在changelog文档()中读到,Java Spring引导-从2.2.5升级到2.3.0后验证停止工作,java,spring,spring-boot,validation,Java,Spring,Spring Boot,Validation,我已经将SpringBoot项目从2.2.5迁移到2.3.0,之后,验证停止工作(根本不调用它们) 我在changelog文档()中读到,springbootstartervalidation现在需要作为依赖项手动添加 因此,我将其添加到pom.xml中: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-va
springbootstartervalidation
现在需要作为依赖项手动添加
因此,我将其添加到pom.xml中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
编辑:
我能够找到问题,请在下面检查我的答案
谢谢大家的帮助 您好,您必须使用
@Validated
注释对控制器类进行注释参见下面的示例:
出于测试目的,请尝试注释@Validated
注释,您不会注意到javax.validation.ConstraintViolationException:hello.name:size必须介于4和10之间
但一旦你把它放回原处,它就会再次工作。
更多的技术信息在这里
@springboot应用程序
公共类演示应用程序{
公共静态void main(字符串[]args){
run(DemoApplication.class,args);
}
@验证
@RestController
@请求映射(“/hello”)
类Hello控制器{
@GetMapping
公共字符串hello(@Valid)
@NotNull(message=“Name不能为空”)
@大小(最小为4,最大为10)@RequestParam(“名称”)字符串名称{
返回“你好,”+name+“!”;
}
}
}
4.0.0
org.springframework.boot
spring启动程序父级
2.3.0.1发布
com.example
演示
0.0.1-快照
演示
SpringBoot的演示项目
1.8
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动启动器验证
org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机
org.springframework.boot
springbootmaven插件
验证启动器不再包含在web启动器中
spring boot starter验证不再是spring boot starter web和spring boot starter webflux的可传递依赖项
为验证工作添加此依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
org.springframework.boot
弹簧启动启动器验证
实际上,单元测试中存在错误。验证工作进展顺利
对于那些带着同样问题来到这里的人来说,很可能您没有按照Braian Silva的建议将以下依赖项添加到pom.xml中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
org.springframework.boot
弹簧启动启动器验证
谢谢你们的帮助,伙计们 我这里也有类似的问题。但在我的例子中,验证警告我oracle模式中缺少一个序列,但它确实存在。我认为这是一个错误。。根据spring boot 2.3.1版本,我将继续使用2.4.0版本 不再包含使用spring starter的spring boot starter验证 如何在上添加初学者验证 maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
审核放行单
解决上述问题的简单方法是添加:
<repositories>
<repository>
<id>Central Maven repository</id>
<name>Central Maven repository https</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
中央Maven存储库
中央Maven存储库https
https://repo.maven.apache.org/maven2
违约
假的
到POM.xml文件。
这将解决此版本的问题
Vipul.如果您遇到以下问题,例如:无法看到返回到客户端的验证错误(默认消息),您可以这样做: 顶级解决方案1: 只需添加devtools。这应该可以解决问题。完成此操作后,所有绑定结果都返回给客户机。我建议您先测试一下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
解决方案3:(在我发现同样有用的解决方案2之前)
所以我发现这是因为有了SpringBoot2.3+。但是我在SpringBootV2.3+中找不到关于@Valid的新更新用法的警告消息
因此,通过调整pom.xml文件中的发布版本,我最终切换回Spring boot v2.2.10(2.2的最新版本),如下所示:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
org.springframework.boot
spring启动程序父级
2.2.10.发布
通过回滚到旧版本,这对我来说非常有效。虽然我想有一天更新我的Spring Boot版本。(重温解决方案1和2)能否显示完整的pom.xmlplz@CodeScale我的pom非常复杂(几个maven模块有很多依赖项和插件)。我已经添加了这个部分。还有什么你感兴趣的吗?谢谢你的帮助。你可以参考这里这是springs的实现,试着将@Validated添加到你的controller@silentsudo它在从SpringBoot2.2.5迁移到2.3之前就已经工作了。0@martins.tuga你做过前后的类路径比较吗?谢谢你的回答。它在从spring boot 2.2.5迁移到2.3.0之前就已经工作了。尽管如此,我还是用@Validated进行了测试,但无论如何它都不工作。@silentudo。。似乎不合逻辑。。我们在这里讨论一个小版本,所以“不”破坏更改。。。它应该可以工作,而不改变任何代码…你可以分享任何样本项目,因为我刚刚创建了这个hello工作样本,它开始工作,或者我们可能会在聊天室它你仍然有问题后,使这项工作upgrade@ntholi在SpringBootVersion2.3.0中,需要在上面添加此依赖项才能工作,并在我的屏幕上使用ValidationWerid就是说,我把
spring启动程序验证看作是外部依赖,但它根本不起作用
dependencies {
...
implementation 'org.springframework.boot:spring-boot-starter-validation'
}
<repositories>
<repository>
<id>Central Maven repository</id>
<name>Central Maven repository https</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
server.error.include-message=always
server.error.include-binding-errors=always
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>