2017-11-10 6 views
0

私は自分のプロジェクトでヘイゼルキャストを使用しており、ヘビキャストのホスト:ポート情報を環境変数に移動することはありません。 Spring BootでHazelcastホストポートを設定するには?

<hazelcast-client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.hazelcast.com/schema/client-config 
           http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.8.xsd" 
        xmlns="http://www.hazelcast.com/schema/client-config"> 

    <network> 
     <connection-timeout>3000</connection-timeout> 
     <connection-attempt-period>1000</connection-attempt-period> 
     <connection-attempt-limit>259200</connection-attempt-limit> 
    </network> 

</hazelcast-client> 

は、だから私は、カスタム <address> hazelcastインスタンスのために提供するために、 <network><cluster-members>タグを追加することが可能があることを発見しました。その前に私は次のように見えたデフォルト設定を持っていました。私はに私の hazelcast.xmlファイルを変更した:

<network> 
    <cluster-members> 
     <address>${HAZELCAST_URL}</address> 
    </cluster-members> 
    ... 

しかし、私は私のアプリを起動していたときにそれが示しています

2017-11-10 17:55:45 [service,,,] WARN c.h.c.s.i.ClusterListenerSupport hz.client_0 [dev] [3.8.5] Exception during initial connection to ${HAZELCAST_URL}:5701, exception java.lang.IllegalArgumentException: Can't resolve address: ${HAZELCAST_URL}:5701 
2017-11-10 17:55:45 [service,,,] WARN c.h.c.s.i.ClusterListenerSupport hz.client_0 [dev] [3.8.5] Exception during initial connection to ${HAZELCAST_URL}:5702, exception java.lang.IllegalArgumentException: Can't resolve address: ${HAZELCAST_URL}:5702 

だから、それはまだポートをデフォルトにしても、変数が解決されていない接続しようとします。それを設定する方法はありますか?

答えて

0

java.util.Propertiesをクライアント設定ビルダーに渡すことができます。あなたはSpringの環境から構築するだけです。

@Bean 
public ClientConfig clientConfig(Environment environment) throws Exception { 
     Properties properties = new Properties(); 
     String HAZELCAST_URL = "HAZELCAST_URL"; 
     properties.put(HAZELCAST_URL, environment.getProperty(HAZELCAST_URL)); 
     XmlClientConfigBuilder xmlClientConfigBuilder = new XmlClientConfigBuilder("hazelcast-client.xml"); 
     xmlClientConfigBuilder.setProperties(properties); 
     return xmlClientConfigBuilder.build(); 
} 

@Bean 
public HazelcastInstance hazelcastInstance(ClientConfig clientConfig) { 
     return HazelcastClient.newHazelcastClient(clientConfig); 
} 

注、これを行うにはよりエレガントな方法は、上記ただ一つの解決策は

できるだけ簡単にそれを維持され、そこにあります
関連する問題