spring - How can I parse a property and inject values back into the Environment? -


i have property parse , inject values environment. make these values available using @value annotation.

eg. properties file or system property:

settings.compoundproperty=abc.xyz.123 

i parse , inject

prop1=abc prop2=xyz prop3=123 

back environment. able inject these new properties in bean follows:

@value("${prop1}") prop1;  @value("${prop2}") prop2; 

i tried this:

@configurationproperties (prefix="settings") public class environmentproperties {       @inject configurableenvironment env;        public void setcompoundproperty(string s) {            // parse s , inject prop1, prop2 , prop3 using env       } 

however works if include

@inject environmentproperties envprops;  

in class @value("${prop1}") prop1; attributes.

how can without needing include envprops mentioned above ?

you can use spring expression language (spel)

all properties can accessed using environment in code below accessing prop1 , inject in value string

@value("#{environment.prop1}") private string value; 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

node.js - How to mock a third-party api calls in the backend -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -