We store in Zookeeper nodes some standard configuration for multiple cases. It is a flat list of simple values (string, boolean, integer etc). So for now we have a class describing this config, with corresponding fields, and fill its instances using ConfigurationProperties annotation with different prefixes.
class DatasourceConfig {
var pid: String? = null
var className: String? = null
var poolSize: Int = 30
var minIdle: Int = 10
var maxIdle: Int = 10
var conTimeout: Long = 100500
...
}
The problem is that now we need to read several instances of this config from the node with underscore in the path. ConfigurationProperties does not support snake case or camel case in the prefix, only kebab case.
@ConfigurationProperties(prefix = "smth.new_path.datasources.aaa")
fun aaaDataSourceConfig() = DatasourceConfig()
@ConfigurationProperties(prefix = "smth.new_path.datasources.bbb")
fun bbbDataSourceConfig() = DatasourceConfig()
this results in error:
APPLICATION FAILED TO START
***************************
Description:
Configuration property name 'new_path' is not valid:
Invalid characters: '_'
Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must start with a letter
There is no opportunity to rename the node. It is not an option.
Zookeper root node is set using spring.cloud.zookeeper.config.root in bootstrap.yml, and I guess Spring Cloud Zookeeper is used to read values. If I set this root to "new_path", ConfigurationProperties works, but I also need values from other paths in my application.
Configuration list is quite long and used multiple times, so I would like to avoid using @Value annotation for each attribute.
Is there any other way than ConfigurationProperties, or maybe any way to tweak ConfigurationProperties or Spring Cloud Zookeeper to make it work together?