user5475461
user5475461

Reputation: 31

Spring configuration method call to pass Calendar.YEAR

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

Answers (1)

codependent
codependent

Reputation: 24452

You almost had it, use the #{} placeholder:

<list>
      <value type="int">#{currCalendar.YEAR}</value>
      <value type="int">-50</value>
</list>

Upvotes: 1

Related Questions