1

我是 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)

任何想法如何让兵马俑工作?

4

1 回答 1

1

我想你已经混合了所需的陶罐。如果您使用 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
于 2013-03-29T13:04:21.317 回答