您好我正在使用默认配置版本并运行spring + JPA + Hibernate + Hazelcast进行二级缓存。 在我的一个服务器上创建了多个hazelcast节点,下面是我的配置
<group>
<name>user-dev</name>
<password>user-dev-pass</password>
</group>
<property name="hibernate.cache.hazelcast.instance_name">SERVER1_HAZELCAST</property>
<management-center enabled="true">http://localhost:8080/mancenter-3.1.8</management-center>
<network>
<port auto-increment="true" port-count="100">5711</port>
<outbound-ports>
<!--
Allowed port range when connecting to other nodes.
0 or * means use system provided port.
-->
<ports>0</ports>
</outbound-ports>
<join>
<multicast enabled="false">
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54320</multicast-port>
</multicast>
<tcp-ip enabled="true">
<interface>127.0.0.1:5710</interface>
</tcp-ip>
</join>
<interfaces enabled="false">
<interface>10.10.1.*</interface>
</interfaces>
<ssl enabled="false" />
<socket-interceptor enabled="false" />
Below are the logs:
Members [4] {
Member [127.0.0.1]:5710 this
Member [127.0.0.1]:5711
Member [127.0.0.1]:5712
Member [127.0.0.1]:5713
}
16:37:25,555 INFO [com.hazelcast.cluster.ClusterService] (hz.WS-DBCacheInstance.cached.thread-7) [127.0.0.1]:5711 [user-dev]
Members [4] {
Member [127.0.0.1]:5710
Member [127.0.0.1]:5711 this
Member [127.0.0.1]:5712
Member [127.0.0.1]:5713
}
任何人都可以帮助我
编辑后添加了代码: -
@Configuration
public class HazelcastConfig {
private static final String INSTANCE_NAME = "mycache";
private static final String HAZELCAST_CONFIG_XML = "hazelcast.xml";
@Bean
public HazelcastInstance hazelcastInstance() {
HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(INSTANCE_NAME);
if (instance == null) {
Config config = new ClasspathXmlConfig(HAZELCAST_CONFIG_XML);
config.setInstanceName(INSTANCE_NAME);
config.setProperty("hazelcast.logging.type", "none");
instance = Hazelcast.newHazelcastInstance(config);
}
return instance;
}
@Bean
public HazelcastCacheManager cacheManager(HazelcastInstance hazelcastInstance) {
return new HazelcastCacheManager(hazelcastInstance);
}
答案 0 :(得分:1)
好的,让我试着改写你的问题,我希望我做对了。您想使用Hazelcast(普通)和Hazelcast Hibernate集成吗?您的Hibernate配置和您自己创建的Hazelcast实例必须具有相同的名称。或者,您可以将Hibernate集成配置为Hazelcast客户端以连接到您的群集。
https://github.com/hazelcast/hazelcast-hibernate#setting-client-server-for-hibernate http://docs.hazelcast.org/docs/3.8/javadoc/com/hazelcast/core/Hazelcast.html#getHazelcastInstanceByName-java.lang.String-