java - How to customize properties binding from enriroment variables using Spring Boot -


i binded properties environment variable map. if property defined in application.properties binding works correctly. if property defined env variable bindings fails.

consider following example:

@configurationproperties("com.test") public class props {     private map<string, map<string, string>> property; } 

following env variable expected mapped map [property={foo={bar=value}}].

export com_test_property_foo_bar=value  

but binding failing

failed convert property value of type 'java.lang.string' required type 'java.util.map' property 'property[foo_bar]'; nested exception java.lang.illegalstateexception: cannot convert value of type 'java.lang.string' required type 'java.util.map' property 'property[foo_bar]': no matching editors or conversion strategy found 

based on documentation i've tried create custom converter , using @configurationpropertiesbinding register approach not able access keys, values.

i've tried register custom propertyeditor, looks not getting registered, maybe should registered in different way?

@bean @configurationpropertiesbinding public customeditorconfigurer customeditorconfigurer() {     customeditorconfigurer pe = new customeditorconfigurer();     pe.setcustomeditors(collections.singletonmap(map.class, keypropertyeditor.class));     return pe; } 

you can try out using demo app


edit 1 i've raised an issue


edit 2

it fixed in spring boot 2

edit : regarding want : use following application.properties file.

com.test.some.key=${com_test_property_some_key} com.test.other.key=${com_test_property_other_key} 

i know it's bothersome should trick.

you can post-process every properties starting com_test_property, parse them, split them path want , inject them environment require more code.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -