@Bean PropertiesFactoryBean not loading properly
Hello,
I am trying to switch my application from XML config to Java config and I'm running into some problems with Properties
On a side note, I need to have a separate PropertiesFactoryBean, since I reuse them in a controller, but everything else uses the PlaceHolderConfiguration
This is my original configuration, and everything works perfectly :
Code:
<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>file:etc/application.properties</value>
</list>
</property>
</bean>
<bean id="applicationConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties" ref="applicationProperties" />
<property name="ignoreUnresolvablePlaceholders" value="false" />
</bean>
And then I tried to switch it to Java config like this :
Code:
@Bean(name="applicationProperties")
public static PropertiesFactoryBean applicationPropertiesFactoryBean() {
PropertiesFactoryBean ppc = new PropertiesFactoryBean();
ppc.setLocations(new Resource[] {
new FileSystemResource("etc/application.properties")
});
ppc.setIgnoreResourceNotFound(true);
return ppc;
}
public static Properties applicationProperties() throws Exception {
return applicationPropertiesFactoryBean().getObject();
}
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setProperties(applicationProperties());
ppc.setIgnoreResourceNotFound(true);
ppc.setIgnoreUnresolvablePlaceholders(false);
return ppc;
}
Yet every single time the properties are accessed, it always returns null
- I've tried setting up the FactoryBean not static
- I've tried removing it from the PlaceholderConfig and using it only in my Controller
- I've tried many little changes left and right, and it's still null when I call it
Am I missing something?
Or is there a problem with PropertiesFactoryBean?
I ended up setting the applicationProperties in XML, and using the setLocations for my PlaceHolder, and everything works fine, but I'd like to bring everything in Java with the annotations
Thanks