是否可以在hazelcast.xml
。
示例:
在hazelcast.xml
文件中,
<context:property-placeholder location="/home/local/Documents/testproperty/test.properties"/>
使用上述标记加载属性文件,并使用hazelcast xml中的属性值,如下所示
<properties>
<property name="hazelcast.max.no.heartbeat.seconds" value = "${HAZELCAST_MAX_NO_HEARTBEAT_SECONDS}"></property>
<property name="hazelcast.client.heartbeat.timeout" value = "${HAZELCAST_CLIENT_HEARTBEAT_TIMEOUT}"></property>
还有其他方法可以在xml中加载属性值吗?
注意:使用加载到应用程序中 配置cfg = new XmlConfigBuilder(xmlFileName).build();
谢谢, 哈利
答案 0 :(得分:3)
哈利,
以下是如何做到这一点
AfterUpdate
hazelcast.xml
Birthdate
// our you can inject this using Spring
Properties properties = new Properties();
properties.load(CurrentClass.class.getClassLoader().getResourceAsStream("hazelcast.properties"));
final Config config = new XmlConfigBuilder("hazelcast-with-properties.xml")
.setProperties(properties) // this is how you can set the properties
.build();
final HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.6.xsd"
xmlns="http://www.hazelcast.com/schema/config">
<properties>
<!-- pay attention to the format - property tag doesn't have value attribute -->
<property name="hazelcast.max.no.heartbeat.seconds">${HAZELCAST_MAX_NO_HEARTBEAT_SECONDS}</property>
<property name="hazelcast.client.heartbeat.timeout">${HAZELCAST_CLIENT_HEARTBEAT_TIMEOUT}</property>
<property name="hazelcast.backpressure.enabled">${HAZELCAST_BACKPRESSURE_ENABLED}</property>
</properties>
<group>
<name>${group.name}</name>
<password>${group.password}</password>
</group>
</hazelcast>
那应该做的事情。
谢谢