维护别人的项目的时候遇到一个问题,@Validated怎么都不生效
解决:
老项目使用的
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
修改成
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
原因是依赖没有被解析
Validation Starter no longer included in web starters
As of #19550, Web and WebFlux starters do not depend on the validation starter by default anymore. If your application is using validation features, for example you find that javax.validation.* imports are not being resolved, you'll need to add the starter yourself. For Maven builds, you can do that with the following:
Spring Boot验证不生效:迁移依赖与解决策略
在维护项目时,遇到@Validated注解失效的问题。原项目依赖于旧版validation-api,需升级到spring-boot-starter-validation。关键在于确认Web启动器不再默认包含Validation Starter,需手动添加。解决过程涉及依赖解析和配置调整。

被折叠的 条评论
为什么被折叠?



