Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 275
LBOSS Avatar asked Dec 04 '25 18:12

LBOSS


1 Answers

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).

like image 160
Stephane Nicoll Avatar answered Dec 06 '25 10:12

Stephane Nicoll