Daniel
Daniel

Reputation: 1676

Set system property with spEL arithmetic

The following property is configured in a properties file: readTimeout=10. I want to use it to set the system property oracle.jdbc.ReadTimeout, but first multiply it by 1000 (to convert to ms.) I tried the following, which does not work:

<bean id="systemPrereqs"
        class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" value="#{@systemProperties}" />
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <util:map>
            <entry key="oracle.jdbc.ReadTimeout"
                value="#{T(java.lang.Integer).valueOf('${readTimeout}')*1000}" />
        </util:map>
    </property>
</bean>

No oracle.jdbc.ReadTimeout system property gets created.

However, if I use the following expression:
#{'${readTimeout}'*1000} then it is evaluated, and oracle.jdbc.ReadTimeout system property is created, but with 101010.... (a thousand repetitions).

Seems that Spring has a problem with type conversion using T(java.lang.Integer).valueOf. Maybe because the spEL expression is not supported in util:properties/map definitions.

Upvotes: 2

Views: 1161

Answers (1)

mike_m
mike_m

Reputation: 1546

Don't use '${readTimeout}', readTimeout will work fine:

<entry key="oracle.jdbc.ReadTimeout" value="#{new Integer(readTimeout) * 1000}" />

Upvotes: 1

Related Questions