我在服务器端所做的更改:
this
我将从我的属性文件中获取我的组名和密码。
我的客户端代码:
@Bean(name = {"hazelcast"})
public HazelcastInstance hazelcastInstance() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getGroupConfig().setName(integrationSettings.getHazelcastClusterGroupName())
.setPassword(integrationSettings.getHazelcastClusterGroupPass());
final ClientNetworkConfig clientNetworkConfig = new ClientNetworkConfig();
clientNetworkConfig.addAddress("127.0.0.1:6701");
clientConfig.setNetworkConfig(clientNetworkConfig);
clientConfig.setInstanceName("INTEGRATION_INSTANCE");
final String hazelcastEnterpriseLicenseKey = null;
if (hazelcastEnterpriseLicenseKey != null) {
clientConfig.setLicenseKey(hazelcastEnterpriseLicenseKey);
}
return HazelcastClient.newHazelcastClient(clientConfig);
}
我的错误日志:
ClientConfig clientConfig = new ClientConfig();
clientConfig.getGroupConfig().setName(hazelcastGroupName).setPassword(hazelcastGroupPwd);
clientConfig.getNetworkConfig().addAddress(serverAddress);
hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
我需要将我的hazelcast作为客户端连接,但是此bean异常导致部署失败。有没有其他方法可以做到这一点?
答案 0 :(得分:0)
查看您的代码,您将在服务器端和客户端创建“Hazelcast-Client”。在服务器端代码中,请通过传递“Config”对象而不是“ClientConfig”更像
来创建hazelcast ServerMember实例的
的@Bean
public HazelcastInstance hazelcastInstance() throws Exception {
Config cfg = new Config();
...
...
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
return instance;
}
的
Hazelcast客户端可以连接到Hazelcast ServerMember。您还需要确保在客户端可以连接之前启动ServerMember。