我是EHCache的新手,并试图将其用作我们的缓存服务器。我编写了尝试入门的代码:
public class CacheMap {
private static CacheManager cacheManager=new CacheManager("ehcache.xml");
private static Cache cache=cacheManager.getCache("firstCache");
}
在类路径中,我包括了terracotta-toolkit-1.6-5.2.0.jar,terracotta-toolkit-1.6-runtime-5.0.0,slf4j-api-1.6.6,slf4j-jdk14-1.6.6,ehcache-2.7。 0和ehcache-ee-2.7.0
我的根目录中有ehcache.xml。
但是,我的代码第一行出现以下错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: net.sf.ehcache.CacheException: Could not create ClusteredInstanceFactory due to missing class. Please verify that terracotta-toolkit is in your classpath.
at net.sf.ehcache.terracotta.TerracottaClusteredInstanceHelper.newClusteredInstanceFactory(TerracottaClusteredInstanceHelper.java:187)
at net.sf.ehcache.terracotta.TerracottaClient.createNewClusteredInstanceFactory(TerracottaClient.java:169)
at net.sf.ehcache.terracotta.TerracottaClient.createClusteredInstanceFactory(TerracottaClient.java:126)
at net.sf.ehcache.CacheManager.doInit(CacheManager.java:442)
at net.sf.ehcache.CacheManager.init(CacheManager.java:392)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:291)
at CacheMap.<clinit>(CacheMap.java:7)
任何想法如何使兵马俑工作?
最佳答案
我认为您混合了所需的兵马俑罐子。如果您使用Maven,则这里是terracotta ver的依赖项。 3.6.5(与JDK5兼容的最新版本):
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core-ee</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-terracotta-ee</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.terracotta</groupId>
<artifactId>terracotta-toolkit-1.5-runtime-ee</artifactId>
<version>4.5.0</version>
</dependency>
另外,不要忘记指向terracotta的Maven存储库以下载所需的jar:
<repository>
<id>terracotta-repository</id>
<url>http://www.terracotta.org/download/reflector/releases</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
如果您不使用maven,则应在类路径上具有以下jar:
ehcache-core-ee-2.5.6.jar
ehcache-terracotta-ee-2.5.6.jar
terracotta-toolkit-1.5-runtime-ee-4.5.0.jar
关于java - Terracotta工具包缺少的类阻止EHCache启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15637680/