Reputation: 4991
I have a entry on application.properties like this.
stackoverflow.questiontitle=I cant see this from environment
But in my code I'm unable to see it.
As you can see the @Value is working but this time I need it from Environment or ApplicationContext. How can I do that?
I mean the @Value I can see the property but I need it from Environment on other class, yes it is failing on runtime.
Is running prod profile.
Upvotes: 0
Views: 85
Reputation: 6936
This should work...
import org.springframework.core.env.Environment;
@Component
class WithEnvironment {
WithEnvironment(Environment environment) {
System.out.println(environment.getProperty("stackoverflow.questiontitle"));
}
}
To see the value in IntelliJ IDEA
in debug mode you can use:
((ApplicationEnvironment)environment).getProperty("stackoverflow.questiontitle")
add a New Class Level Watch...
on environment
with getProperty("stackoverflow.questiontitle")
Upvotes: 1