1

I want to set property in spring-context.xml file and instantiate the class which have one setter method of long dataType.

package com.mob.test;

class Test
{

private long timeInMillis;

//getter and setter
}

test.properties

TIME_IN_MINUTES=10

Spring-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">


    <context:property-placeholder location="classpath:test.properties"/>    

    <bean id="ready"
        class="com.mob.test.Test">
        <property name="timeInMillis" value="${TIME_IN_MINUTES}*60*1000"/>
    </bean>
</beans>

gives NumberFormateException.

How can i solve this problem.

P.K.Hindustani
  • 128
  • 1
  • 4
  • 12

1 Answers1

1

Try with this:Expression support for defining bean definitions

#{ systemProperties['TIME_IN_MINUTES'] * 60 * 1000 }
Erik Lucio
  • 948
  • 7
  • 8