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;