I added to my application.yml the following section:
app:
host: server.com
I injected the Environment to my class (RestController):
@Autowired
private Environment environment;
But reading the value returns null:
System.out.println( environment.getProperty( "app.host" ) );
What is the correct way to achieve that? Will it be the same for nested properties like 'app.config.serviceA.host' ?
Try using a class variable with the value annotation inside any annotated class @Component, @Repository, etc..
@Value("${app.host}")
private String host;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With