Kotlin spring-boot nested config props
This repository demonstrates how Kotlin can simplify Spring Boot configuration properties file mapping
@ConstructorBinding
@ConfigurationProperties("my.nested.config.props")
data class MyNestedConfigProps(
val parentField1: String = "undefined",
val parentField2: String = "undefined",
val child: Child = Child(),
)
data class Child(
val childField1: String = "undefined",
val childField2: String = "undefined",
)
@SpringBootApplication
@EnableConfigurationProperties(MyNestedConfigProps::class)
class MainApp
fun main(args: Array<String>) {
runApplication<MainApp>(*args)
}
map to next zapplication.properties` file:
my.nested.config.props.parent-filed-1=parent-field-1-value
my.nested.config.props.parent-filed-2=parent-field-2-value
my.nested.config.props.child.child-filed-1=child-field-1-value
my.nested.config.props.child.child-filed-2=child-field-2-value
or to next application.yaml
file:
my.nested.config.props:
parent-field-1: parent-field-1-value
parent-field-2: parent-field-2-value
child:
child-field-1: child-field-1-value
child-field-2: child-field-2-value