Java 在Hazelcast XML配置中使用属性文件值
是否可以在Java 在Hazelcast XML配置中使用属性文件值,java,xml,properties,hazelcast,Java,Xml,Properties,Hazelcast,是否可以在hazelcast.xml中加载属性文件值 例如: 在hazelcast.xml文件中 <context:property-placeholder location="/home/local/Documents/testproperty/test.properties"/> 使用上述标记加载属性文件,并使用hazelcast xml中的属性值,如下所示 <properties> <property name="hazelcast.max.no.hea
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中加载属性值
注意:使用
Config cfg=新的XmlConfigBuilder(xmlFileName).build()
谢谢,
哈利哈利
下面是你如何做到这一点的
// 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);
hazelcast.xml
<?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>
那应该可以
谢谢您对我们的实施没有100%的把握,但您是否尝试过Hazelcast的默认物业更换策略?即使我们也尝试过使用FileSystemConfig和properties,它的工作原理也很简单。对于客户端配置,我们有相同的选项吗?我现在眼前没有客户端的java文档,但是,我非常确定java客户端XML配置也可以有相同的选项
group.name=devFromProp
group.password=supA$ecret42
HAZELCAST_MAX_NO_HEARTBEAT_SECONDS=5
HAZELCAST_CLIENT_HEARTBEAT_TIMEOUT=500
HAZELCAST_BACKPRESSURE_ENABLED=true