Code:
@Component // i think requires <context:component-scan .../> or just declare your bean in your Spring XML.
public class FooBean {
public String getPropertyValue() {
return "Hello World!";
}
}
public class Bar {
@Value(#{fooBean.propertyValue})
private String propVal;
public String getPropVal() {
return this.propVal; // will return "Hello World!"
}
}
When Spring starts up, it will create a bean with the name of "fooBean" and then using Spring EL (note the # instead of the $) you can set the value of field based on a bean method (bean rules apply, they do for getters anyway).