Take the 2-minute tour ×

I've never worked with Spring before, and I've run into a configuration object that looks somewhat like this

public class Config {

private String config1;

private String config2



public String getConfig1() {
    return config1;


Can anyone explain what is happening here? I'm assuming this is some type of code injection, but I can't find where these values are coming from!

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

They allow you to direct inject a Value from a properties file (system or declared property) in the variable. Using the util:properties tag you can add something like this in your applicationContext.xml

 <util:properties id="message" location="classpath:com/your/program/resources/message.properties" />

Pointing for a properties file named "message.properties" with some content:

 application.hello.message = Hello World!

And then, in your java source file, inject a direct value from this properties file using the @Value annotation:

 private String helloWorldMessage;
share|improve this answer
Good answer, thanks. Where can I find applicationContext.xml in the file structure? It's a pretty big bit of software. –  J.Ashworth Oct 19 '12 at 4:47
They can be found in the WEB-INF directory, usually a good hint to find out the file (althought is usually named applicationContext.xml it could take any name) is to check out the web.xml file in search for the contextConfigLocation context-param –  h3nr1x Oct 19 '12 at 4:50
add comment


This is part of the spring expression language where the spring framework would look for app.module.config1 JVM property from System.getProperties() and injects the value of that property into config1 attribute in that class. Please see this reference for more details.

share|improve this answer
add comment

Your Answer


