LBOSS
LBOSS

Reputation: 132

Spring boot YAML config : Parametred keys

Is spring boot allow to use parametred keys using YAML ?

Example of parametred key:

myapp.configured.key: This is your email > {0} And this is your name > {1}

And in my Java class i want to do some thing like this:

@Inject
private Environment env;//import org.springframework.core.env.Environment;


String email = "[email protected]"
String name = "User Name";

String key=env.getProperty("myapp.configured.key", email, name);

System.out.println(key);

And the out put will be like this :

This is your email > [email protected] And this is your name > User Name

Upvotes: 3

Views: 1301

Answers (1)

Stephane Nicoll
Stephane Nicoll

Reputation: 33091

If your email and name are also configuration keys, you can refer to them in your message (but it's a bit weird)

myapp.configured.email: [email protected]
myapp.configured.name: John Smith
myapp.configured.key: This is your email > ${myapp.configured.email} And this is your name > ${myapp.configured.name}

The Environment has no such API and as a Spring Boot user you shouldn't even touch that stuff (check @ConfigurationProperties for type safe binding of configuration).

Upvotes: 2

Related Questions