我是科特林新手。我正在尝试实现同样的目标,我会用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
Run Code Online (Sandbox Code Playgroud)
然后我想创建数据类,这样,当我运行 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
)
Run Code Online (Sandbox Code Playgroud)
但它总是在编写 ConstructorBinding 的两个地方抛出此异常
Kotlin:此注释不适用于目标“类”
springboot 3.0.0、java 18、kotlin 1.7.21
我试图从这样的资源中获取图像:
<img src="#{resource['img/bla.svg']}"/>
Run Code Online (Sandbox Code Playgroud)
像这样工作
但是现在我想对此文件进行一般化,因此它将来自这样的java类:
LogoHandler.getLogo(String type)
Run Code Online (Sandbox Code Playgroud)
我试图像这样将它们放在一起:
<img src="#{resource["#{logoHandler.getLogo("A1")}"]}"/>
Run Code Online (Sandbox Code Playgroud)
但是它当然不起作用,只是为了向您展示我想要达到的目标。
你能帮我吗?