It’s a good idea to resolve the configuration properties from external files and Spring supports this feature which is quite easy to use. You just need to put the properties file(s) in the classpath, for example in the Maven application APP_ROOT/src/main/resources/application.properties. Let’s modify the SimplePoem class from our previous example of spring to have the poem string resolved from the application.properties file:

public class SimplePoem implements Poem {
    @Value("${poem}")
    String poem;
    public void recite(){
        System.out.println(poem);
    }
}

For @Value to work, you will have to add the following line of code to your spring config file which will configure all the annotated properties.

<context:annotation-config/>

Finally, you will have to mention the application.properties in the spring config file like this:

<context:property-placeholder location="classpath:application.properties" />

and your application.properties file looks like this:

application=SpringCoreAnnotation
poem=Resolving poem from the properties file...