1

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.