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-テラコッタ-ee-2.5.6.jar
  • テラコッタ-ツールキット-1.5-ランタイム-ee-4.5.0.jar
于 2013-03-29T13:04:21.317 に答える