Create map of lists from Spring config in Kotlin
It works fine for me when the map is inside a "prefix" which is recommended for spring boot configurations.
My yml:
apiconfig: myNewMap: firstKey: - 2 - 4 secondKey: - 2
and my config class:
@Component@ConfigurationProperties(prefix = "apiconfig")class ApiConfiguration { var myNewMap: Map<String, List<String>>? = null}
usage class:
@RestControllerclass Apis(@Autowired private val apiConfiguration : ApiConfiguration) { @GetMapping("/test") fun test(): String { apiConfiguration.myNewMap return "test" }}
For whoever still having this, the @Component
interface won't help you, you need @ConstructorBinding
.
@ConstructorBinding@ConfigurationProperties(prefix = "apiconfig")class ApiConfiguration { var myNewMap: Map<String, List<String>>? = null}