Reputation: 163
I am trying to access some properties programmatically in a controller of a spring mvc application. I configured it by xml. I tried both PropertyPlaceholderConfigurer
and <context:property-placeholder />
I tried to use in the controller class(saw it in a working example but it was configured with @Configuration
):
@Inject
private Environment environment;
and afterwards i use:
environment.getProperty("upload.location")
but i get a null value. The entry exists in the properties file(i have only one) and also using ${...}
in the xml works
Upvotes: 1
Views: 6004
Reputation: 9255
A much simpler way - use @Value
to inject the system property, as follows:
private @Value("${systemPropertyFoo}") String systemPropertyFoo;
In your case (I"m assuming the variable is a system property):
private @Value("${upload.location}") String uploadLocation;
This annotation depends on the PropertyPlaceholderConfigurer
, so keep it in your config.
Upvotes: 3