我们可以在xml中读取.properties文件吗?

时间:2016-07-12 07:36:41

标签: java xml java-ee properties

我有一个包含值的.properties文件。我试图将其中一个值设置为xml文件中的字段。 例如,会话到期在属性文件中设置为300秒。 所以我需要在xml文件中设置相同的值。

<max-idle-seconds>300</max-idle-seconds> 

这个300应该来自.properties文件。 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:-1)

是。在代码下面添加XML。

<context:property-placeholder location="classpath:your_property_filename.properties"  ignore-unresolvable="true"/>

或者你可以写:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" lazy-init="false">
    <property name="locations">
        <list>
            <value>classpath:your_property_filename.properties</value>
        </list>
    </property>
</bean>
相关问题