Reputation: 31
I am trying to pass this arguments to the method call Calendar.add(Calendar.YEAR, -10) in the Spring config. How to pass Calendar.YEAR which is actually an int, but Spring config treats it as a String and throws error.
It works if I call without Spring like:
from = from.add(Calendar.YEAR, -10);
Config:
<bean id="currCalendar"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.util.Calendar"/>
<property name="staticMethod">
<value>java.util.Calendar.getInstance</value>
</property>
</bean>
<bean id="from1"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<ref local="currCalendar"/>
</property>
<property name="targetMethod" value="add"/>
<property name="arguments">
<list>
<value type="int">currCalendar.YEAR</value>
<value type="int">-50</value>
</list>
</property>
</bean>
Please suggest how to do in Spring
Upvotes: 1
Views: 442
Reputation: 24452
You almost had it, use the #{}
placeholder:
<list>
<value type="int">#{currCalendar.YEAR}</value>
<value type="int">-50</value>
</list>
Upvotes: 1