I faced the issue after upgrade SpringBoot from 2.x to 3.0.1 In kotlin, @ConfigurationProperties deosn't generate 'peroperteis' field in some conditions.
1.
Code
: 'var' with default value
@ConfigurationProperties(prefix = "cnr.app")
data class AppProperties(
var name: String = "cma",
var version: String = "0.0.1"
)
spring-configuration-metadata.json
{
"groups": [
{
"name": "cnr.app",
"type": "studio.m2s.cnr.cma.AppProperties",
"sourceType": "studio.m2s.cnr.cma.AppProperties"
}
],
"properties": [
{
"name": "cnr.app.name",
"type": "java.lang.String",
"sourceType": "studio.m2s.cnr.cma.AppProperties"
},
{
"name": "cnr.app.version",
"type": "java.lang.String",
"sourceType": "studio.m2s.cnr.cma.AppProperties"
}
],
"hints": []
}
result
: Good
2.
Code
: 'val' with default value
@ConfigurationProperties(prefix = "cnr.app")
data class AppProperties(
val name: String = "cma",
val version: String = "0.0.1"
)
spring-configuration-metadata.json
{
"groups": [
{
"name": "cnr.app",
"type": "studio.m2s.cnr.cma.AppProperties",
"sourceType": "studio.m2s.cnr.cma.AppProperties"
}
],
"properties": [],
"hints": []
}
result
: Bad.
In Spring Boot 3.0.1
- If I declare fields with 'var', it works good.
- If I declare fields with 'val', it works
bad
. - If I declare fields with 'var' without default value, it works good.
- If I declare fields with 'val' without default value, it works good.
In Spring Boot 2.7.x
- If I declare fields with 'var', it works good.
- If I declare fields with 'val', it works
good
. - If I declare fields with 'var' without default value, it works good.
- If I declare fields with 'val' without default value, it works good.
gradle.kts
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
kapt {
annotationProcessor("org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor")
}
tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(processResources)
}
}
dependencies {
kapt("org.springframework.boot:spring-boot-configuration-processor")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
}
I expect, it works with 'val' with default value.
In Spring Boot 3.0.1
- If I declare fields with 'var', it works good.
- If I declare fields with 'val', it works
good
. - If I declare fields with 'var' without default value, it works good.
- If I declare fields with 'val' without default value, it works good.
like spring boot 2.7.x