如何在spring-context.xml中设置setProperty

时间:2017-05-16 12:02:18

标签: java spring mongodb

我想在spring-context.xml文件中设置属性,并实例化具有long dataType的一个setter方法的类。

package com.mob.test;

class Test
{

private long timeInMillis;

//getter and setter
}

test.properties

TIME_IN_MINUTES=10

弹簧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>

给出NumberFormateException。

我该如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

试试这个:Expression support for defining bean definitions

#{ systemProperties['TIME_IN_MINUTES'] * 60 * 1000 }