I want to convert this XML configuration to Java but I'm some having trouble finding the correct way to do it..
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.lang.System"/>
<property name="targetMethod" value="getProperties"/>
</bean>
</property>
<property name="targetMethod" value="putAll"/>
<property name="arguments">
<util:properties>
<prop key="key1">value1</prop>
<prop key="key2">value2</prop>
<prop key="key3">value3</prop>
<prop key="key4">value4</prop>
<prop key="key5">value5</prop>
</util:properties>
</property>
</bean>
It is almost working fine but I get an error about the putAll method. It should be called on the Properties object but with my Java config (see below) it tries to call it on the MethodInvokingFactoryBean object.
@Bean
public MethodInvokingFactoryBean getMethodInvokingFactoryBean() throws IOException {
final MethodInvokingFactoryBean methodInvokingFactoryBean = new MethodInvokingFactoryBean();
final MethodInvokingFactoryBean target = new MethodInvokingFactoryBean();
target.setTargetClass(System.class);
target.setTargetMethod("getProperties");
methodInvokingFactoryBean.setTargetObject(target);
methodInvokingFactoryBean.setTargetMethod("putAll");
final Properties properties = new Properties();
properties.put("key1", "value1");
properties.put("key2", "value2");
properties.put("key3", "value3");
properties.put("key4", "value4");
properties.put("key5", "value5");
final PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setProperties(properties);
methodInvokingFactoryBean.setArguments(propertiesFactoryBean);
return methodInvokingFactoryBean;
}
So the error I'm getting now is:
java.lang.NoSuchMethodException: org.springframework.beans.factory.config.MethodInvokingFactoryBean.putAll(org.springframework.beans.factory.config.PropertiesFactoryBean) because the putAll should be called on the Properties object.. what am I doing wrong here?