我正在尝试将我的应用程序连接到 Terracotta 缓存集群,但在使用我设置的配置启动应用程序时遇到问题。我在控制台中没有收到任何错误,但如果我进行调试,它在尝试创建 CacheManager 时会失败。
我得到的错误是这样的。引起原因:java.lang.ClassNotFoundException:net.sf.ehcache.config.TerracottaConfigConfiguration
我正在使用 Hibernate 4.x、Spring 4.x、Terracotta BigMemory Max 4.x。
您能告诉我我做错了什么或者在哪里可以找到最新的文档吗?
这些是我的配置:
hibernate 属性:
<prop key="hibernate.cache.use_structured_entries">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="net.sf.ehcache.configurationResourceName">ehcache-hibernate.xml</prop>
Ehcache-hibernate.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache name="ehcache-hibernate"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd">
<cache name="User" maxElementsInMemory="1000"
maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600"
timeToLiveSeconds="1200" memoryStoreEvictionPolicy="LFU">
<terracotta />
</cache>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="1200"
timeToLiveSeconds="1200">
<!--<terracotta />-->
</defaultCache>
<terracottaConfig url="localhost:9510" />
Maven相关依赖:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.10.Final</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-terracotta</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.terracotta</groupId>
<artifactId>terracotta-toolkit-1.6-runtime-ee</artifactId>
<version>5.8.0</version>
</dependency>
<dependency>
<groupId>org.terracotta</groupId>
<artifactId>terracotta-toolkit-runtime-ee</artifactId>
<version>4.1.1</version>
</dependency>
我使用的是 Windows,并且已启动 Terracotta 服务器和管理控制台。服务器显示为 Activity 状态,但没有客户端连接到它。
我尝试使用与我自己类似的环境查找有效配置的示例,但没有找到。
谢谢!
最佳答案
您的类路径中缺少 ehcache-core
。添加以下依赖项以使其正常工作:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.1.1</version>
</dependency>
关于java - 如何将 Terracotta ehcache 与 hibernate 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34750392/