java - 如何在 spring-context.xml 中设置属性

标签 java spring mongodb

我想在spring-context.xml文件中设置属性并实例化具有长数据类型的setter方法的类。

package com.mob.test;

class Test
{

private long timeInMillis;

//getter and setter
}

测试.属性

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>

给出 NumberFormateException。

我该如何解决这个问题。

最佳答案

试试这个:Expression support for defining bean definitions

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

关于java - 如何在 spring-context.xml 中设置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44000925/

相关文章:

java - 类型= FieldType.Object且已启用= false的@Field

javascript - 在 mongo javascript 中使用变量

java - 如何显示组合的算术表达式?就像 (3.3+6.2)*1.2 而不是 9.5 * 1.2

java - 通过 SSH 信任使用 DefaultSftpSessionFactory 进行 SFTP 会引发异常

java - 使用 JDK 1.6.x G1 ("Garbage First"的经验)

java - Thymeleaf ClassLoaderTemplateResolver 找不到电子邮件模板,但只能在 linux 上找到

javascript - Mongoose 保存不正确的值

java - 如何使用 mongodb java 驱动程序进行 CRUD 方法修复 java 中的 'The method MongoClient is undefined' 错误

java - 在@OneToMany JPA集合中使用Where子句

java - 使用线程时出现 StackOverflowError