I’ve never worked with Spring before, and I’ve run into a configuration object that looks somewhat like this
public class Config {
@Value("${app.module.config1}")
private String config1;
@Value("${app.module.config2}")
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!
They allow you to direct inject a Value from a properties file (system or declared property) in the variable. Using the
util:propertiestag you can add something like this in yourapplicationContext.xmlPointing for a properties file named “message.properties” with some content:
And then, in your java source file, inject a direct value from this properties file using the
@Valueannotation: