无法从配置中的属性文件中读取值 XML

Unable to read values from porperties file in config XML

我已将 hazelcast.properties 和 hazelcast config.xml 文件放在类路径中。这是我的目录结构:

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

知道为什么无法从 dev.properties 文件中找到 ${hazelcast.port} 和 ${hazelcast.member} 属性的值吗?

注意:我对休眠二级缓存和我手动配置的缓存映射使用相同的配置文件。

如果您在 系统中定义属性,即 hazelcast.porthazelcast.members 属性,会起作用的。

HazelcastCacheRegionFactory 启动之前从您的 dev.properties 读取这些属性并设置到 System.property。