我有一个在tomcat集群上运行的spring web应用程序(目前有两个tomcats和一个负载均衡器),它具有会话复制和所有好东西..
我的目的是能够以相当简单的方式启动其他tomcats服务器(只是启动)
我目前的问题是属于我的Web应用程序的spring xml文件。
例如 - 我的ehcache.xml:
<!-- Cluster Configuration -->
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
multicastGroupPort=4446, timeToLive=32" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="**hostName=localhost**, **port=40004**, socketTimeoutMillis=2000" />
<defaultCache maxElementsInMemory="50000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" />
正如您所看到的那样,xml中的端口字段和主机名在每个tomcat服务器上都应该是唯一的。 我不想在启动新的tomcat服务器之前手动更改此字段。
有没有解决方案呢?
答案 0 :(得分:0)
我认为有两个主要选择。
1)您可以在运行tomcat时设置系统属性并将其作为变量传递。例如,您可以传递参数-DehcachePort=xxx
,然后在xml集中传递该值为$ {ehcachePort}。我找不到此功能文档的链接,但提到了here
1.1)如果你不能从命令行设置系统属性,你可以编写一个很小的类,在加载ehchache.xml之前调用System.setProperty 。
2)从代码中实例化Ehcache对象。它基本上与上面相同,但您必须读取属性文件并实例化您需要的任何内容。 Ehcache支持流畅的构建器,它易于阅读(与XML的冗长程度相比)。
答案 1 :(得分:0)
EhCachce与Terracoyta完美融合。
如果由于某种原因您不想使用Teracotta,您可以使用Spring的PropertyPlaceholder功能根据环境变量或属性替换它们。