【问题标题】:in kotlin data class, @field:NotBlank not working在 kotlin 数据类中,@field:NotBlank 不起作用
【发布时间】:2021-12-17 01:30:03
【问题描述】:

我们目前使用 jdk 14、spring boot 2.2.8.RELEASE 和 Kotlin 1.5.31。下面的类过去常常在空白的名字或名字上出错。

现在我们正在尝试更新到 Spring Boot 2.5.4,它不再在我们的自动化测试用例中抛出错误。

data class ChangeInformationRequest(
    @field:NotBlank var firstName: String,
    @field:NotBlank var lastName: String,
    @field:Valid var address: Address?
)

【问题讨论】:

    标签: spring-boot kotlin


    【解决方案1】:

    问题是 Spring Boot 验证启动器不再包含在 Spring Boot 2.3 (https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#validation-starter-no-longer-included-in-web-starters) 的 Web 启动器(我猜你正在使用)中。这意味着spring-boot-starter-validation 不再是spring-boot-starter-webspring-boot-starter-webflux 的传递依赖。因此,您必须自己将依赖项实际添加到您的 pom.xml 中,如下所示:

    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
    

    我建议您阅读所有相关的 Spring Boot 发行说明,以便提前了解哪些主要更改可能会影响您的代码:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      • 2021-05-22
      • 2019-07-29
      相关资源
      最近更新 更多