0

I am struggling with following problem in Spring:

I have a very basic class like this:

public class DefaultPropertiesLoader {

    private Properties _defaultProperties;

    public DefaultPropertiesLoader() {}

    public Properties getDefaultProperties() {
        return _defaultProperties;
    }

    public void setDefaultProperties(Properties defaultProperties) {
        _defaultProperties = defaultProperties;
    }
}

and I want the _defaultProperties field to be injected from Spring bean when creating DefaultPropertiesLoader on runtime, for example:

DefaultPropertiesLoader loader = new DefaultPropertiesLoader();
Properties props = loader.getDefaultProperties();

The problem is _defaultProperties field is not injected and stays equal to null.

Here is a snippet of beans definition in Spring configuration file:

<bean class="eu.biosdesign.trading.platform.service.DefaultPropertiesLoader">
    <property name="defaultProperties" ref="defaultSettings"/>
</bean>

<bean id="defaultSettings" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location" value="classpath:default.properties"/>
</bean>

Is this a normal behaviour or am I doing something wrong?

Thanks in advance.

Martin Vrábel
  • 830
  • 1
  • 13
  • 36

0 Answers0