I have a Springboot app that is trying to connect and read values from an app config resource.
Some keys in the Azure app config (which I am unable to change) are in this format
`
/application/config.datasource.jdbc-url
/application/config.datasource.password
/application/config.datasource.username`
I have a config Java class with prefix ("config"), but I don’t know what member variables I should have in order to access "datasource.jdbc-url", "datasource.password" etc.
If the app config was just /application/config.username
then I could just use the below in my Java class
String username;
but for some of the configs that include multiple dots and some dashes (which Java identifiers can’t have), how can I read the values?
Thank you!
3
Answers
Your use case is similar to this sample azure-spring-cloud-starter-appconfiguration-config-sample, please try to define the properties class to bind the configurations in Azure App Configuration.
Adding to @Moarchy Chan
@ConfigurationProperties(prefix = "config.datasource")
In
Azure portal
>App configuration
>Configuration explorer
, I have created keys and values for Username, Password and Jdbc url.This is my Class UserProperties,
Here is the UserController I have created,
This the bootstrap for my code, you should add your connection string in {},
spring.cloud.azure.appconfiguration.stores[0].connection-string= ${APP_CONFIGURATION_CONNECTION_STRING
}This is the output for my Username,
This is the output for my Password,
This is the output for my jdbcurl,
You have two options depending on what you are looking for. You can either use
@Value("config.datasource.jdbc-url")
or you can use nested properties.