Reputation: 1085
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' ?
Upvotes: 4
Views: 7695
Reputation: 2929
Try using a class variable with the value annotation inside any annotated class @Component, @Repository, etc..
@Value("${app.host}")
private String host;
Upvotes: 4