Working with Java Spring, how can I overwrite the default behavior of the property-placeholders to return ‘foo’ for any property?
The current path I’m going down is to extend PropertySource as follows:
public class FooPropertySource extends PropertySource<Object> {
private static final String DEFAULT_NAME = "foo";
public FooPropertySource() {
super(DEFAULT_NAME, null);
}
@Override
public Object getProperty(String name) {
return "foo";
}
}
At this point, I have two questions:
A) What do I do with my application Context XML file? As of now, I’ve defined this as a bean…That’s about it.
B) Do I have to do anything in code to load other beans from my application context, such that they will use the FooPropertySource?
Thanks
You will have to register this PropertySource to be added to your application context. If you manually starting up your application context, you can do this:
If you are doing this in a web environment, you will have to register a custom ApplicationContextInitializer to intercept the application context before it is refreshed to inject in your PropertySource:
More details here