无法从配置XML

时间:2016-09-16 10:50:15

标签: java xml hibernate properties hazelcast

我已经放置了hazelcast.properties& hazelcast config.xml文件,都在classpath中。这是我的目录结构:

resources
|_
| spring-env
| |_
|   dev.properties
|_
  applicationContext-hazelcast.xml

在我的applicationContext-hazelcast.xml中:

<context:property-placeholder file-encoding="UTF-8" location="classpath:spring-env/dev.properties" /> 
<hz:hazelcast id="instance">
    <hz:config>
        <hz:instance-name>hz_instance</hz:instance-name>
        <hz:group name="dev" password="password"/>
        <hz:network port="${hazelcast.port}" port-auto-increment="false">
            <hz:join>
                <hz:multicast enabled="false"/>
                <hz:tcp-ip enabled="true">
                    <hz:members>${hazelcast.members}</hz:members>
                </hz:tcp-ip>
            </hz:join>              
        </hz:network>

一切正常,但是当服务器启动时,会在日志中显示以下内容:

INFO: Configuring Hazelcast from 'file:/E:/.../MyApp/WEB-INF/classes/applicationContext-hazelcast.xml'.
Sep 16, 2016 3:15:47 PM com.hazelcast.config.AbstractConfigBuilder
WARNING: Could not find a value for property  'hazelcast.port' on node: port
Sep 16, 2016 3:15:47 PM com.hazelcast.config.AbstractConfigBuilder
WARNING: Could not find a value for property  'hazelcast.members' on node: null

虽然我在dev.properties文件中指定了这些属性:

#hazelcast properties
hazelcast.port = 35701
hazelcast.members = 127.0.0.1

任何想法为什么它无法找到$ {hazelcast.port}的价值&amp; dev.properties文件中的$ {hazelcast.member}属性?

注意:我正在使用相同的配置文件进行hibernate-second-level cache&amp; amp;对于我手动配置的缓存映射。

1 个答案:

答案 0 :(得分:1)

如果您在系统属性中定义属性,即 hazelcast.port hazelcast.members ,则可以使用。

HazelcastCacheRegionFactory 启动之前,从 dev.properties 中读取这些属性并设置为System.property。