【发布时间】:2022-12-31 01:02:13
【问题描述】:
我是科特林的新手。我正在尝试实现同样的事情,我会用 Java 做。
在 application.yaml 中,我有这个配置:
conference:
plans:
- plan-id: P1_1
product-id: product1
employee-limit: 50
- plan-id: P1_2
product-id: product2
employee-limit: 100
然后我想创建数据类,这样,当我运行 springboot 应用程序时,这个类会自动加载和验证
在 Conferences.kt 文件中:
package com.company.conferenceplanservice.config.properties
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotEmpty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.bind.ConstructorBinding
import org.springframework.context.annotation.Configuration
import org.springframework.validation.annotation.Validated
@Validated
@ConstructorBinding
@Configuration
@ConfigurationProperties(prefix = "conference")
data class Plans(
@field:NotEmpty val plans: Set<Plan>
)
@Validated
@ConstructorBinding
data class Plan(
@field:NotBlank val planId: String,
@field:NotBlank val productId: String,
val eomployeeLimit: Int
)
但它总是在写入 ConstructorBinding 的两个地方抛出这个异常
Kotlin:此注释不适用于目标“类”
springboot 3.0.0,java 18,kotlin 1.7.21
【问题讨论】:
标签: spring-boot kotlin