Read Property Value From Properties File In Spring

The Java properties file can be used to store project configurations or settings.

Environment – Interface representing the environment in which the current application is running.

@Configuration – Configuration classes are candidates for component scanning (typically using Spring XML’s <context:component-scan/> element) and therefore may also take advantage of @Autowired/@Inject at the field and method level (but not at the constructor level).

@PropertySource – Adds property sources to the enclosing Environment.


The values in the properties can be accessed by injecting Environment object to the configuration class.

public class ConstantPropertyInjector {

@Autowired Environment env;

   public ConstantImageHolder getConstantProperty(){
     ConstantImageHolder constant = new ConstantImageHolder ();
     return constant;




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s