我正在尝试设置ehcache复制设置。我有一个使用ehcache的应用程序,它在使用两个服务器的群集环境中运行,并且我试图在两个实例之间建立复制。
以下是我的配置
@Bean(destroyMethod =“关机”) 公共net.sf.ehcache.CacheManager ehCacheManager(){ CacheEventListenerFactoryConfiguration eventListenerFactoryConfig = 新的CacheEventListenerFactoryConfiguration(); eventListenerFactoryConfig.setClass(“ net.sf.ehcache.distribution.RMICacheReplicatorFactory”); eventListenerFactoryConfig.setProperties( “” replicateAsynchronously = true,replicatePuts = true,replicateUpdates = true,replicateUpdatesViaCopy = false,replicateRemovals = true“); eventListenerFactoryConfig.setPropertySeparator(“,”);
BootstrapCacheLoaderFactoryConfiguration bootstrapCacheLoaderFactoryConfig =
new BootstrapCacheLoaderFactoryConfiguration();
bootstrapCacheLoaderFactoryConfig.className("net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory");
bootstrapCacheLoaderFactoryConfig.setProperties("bootstrapAsynchronously=true");
bootstrapCacheLoaderFactoryConfig.propertySeparator(",");
CacheConfiguration userEntityCacheConfiguration = new CacheConfiguration();
userEntityCacheConfiguration.setName("userEntityCache");
userEntityCacheConfiguration.setMaxEntriesLocalHeap(5);
userEntityCacheConfiguration.setTimeToLiveSeconds(3600);
userEntityCacheConfiguration.copyOnRead(true);
userEntityCacheConfiguration.copyOnWrite(true);
userEntityCacheConfiguration.addCacheEventListenerFactory(eventListenerFactoryConfig);
userEntityCacheConfiguration.addBootstrapCacheLoaderFactory(bootstrapCacheLoaderFactoryConfig);
net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
config.addCache(userEntityCacheConfiguration);
FactoryConfiguration<CacheLoaderFactoryConfiguration> peerListenerFactoryConfig = new FactoryConfiguration<>();
peerListenerFactoryConfig
.setProperties("hostName=172.19.16.114,port=40001”);
peerListenerFactoryConfig.setPropertySeparator(",");
peerListenerFactoryConfig.className("net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory");
config.addCacheManagerPeerListenerFactory(peerListenerFactoryConfig);
FactoryConfiguration<CacheLoaderFactoryConfiguration> peerProviderFactoryConfig = new FactoryConfiguration<>();
peerProviderFactoryConfig
.setProperties("peerDiscovery=manual,rmiUrls=“//172.19.16.242:40001/userEntityCache");
peerProviderFactoryConfig.setPropertySeparator(",");
peerProviderFactoryConfig.className("net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory");
config.addCacheManagerPeerProviderFactory(peerProviderFactoryConfig);
config.setMonitoring("autodetect");
config.setDynamicConfig(true);
this.newCacheManager = new net.sf.ehcache.CacheManager(config);
return newCacheManager;
}
这是初审。
对于第二个实例,我将peerListenerFactoryConfig主机名更改为172.19.16.242,并将rmiUrls更改为//172.19.16.114:40001/userEntityCache
缓存功能似乎工作正常,但复制无效
我收到以下异常
[复制线程] 2018-10-26 16:48:12警告 RMIAsynchronousCacheReplicator-无法将消息发送到远程对等方。消息为:连接拒绝托管:127.0.0.1;嵌套的异常是: java.net.ConnectException:连接被拒绝(连接被拒绝) java.rmi.ConnectException:连接被拒绝托管到主机:127.0.0.1;
不确定为什么要尝试访问本地主机。