当前位置: 首页 > 知识库问答 >
问题:

BigMemory 4.0.5 Terrocatta分布式Hibernate二级缓存无法配置

左康安
2023-03-14

我正在使用Bigmemory Max 4.0.5,因为terracotta为我的应用程序分配缓存作为hibernate二级缓存,但是我在服务器启动时遇到了以下异常。

原因:com.tc.config.schema.setup.ConfigurationSetupException:

来自 'localhost:9510' 服务器的基本配置中的配置数据不符合 Terracotta 架构: [0]: 第 7 行,第 5 列:不允许属性(不允许通配符):在元素服务器中安全 [1]:第 9 行,列:元素服务器中的预期元素“服务器”而不是“镜像组” [2]:第 28 行,列 9:元素服务器中的预期元素“服务器”而不是“更新检查”[3]: 第 32 行,第 9 列:元素服务器中的预期元素“server”而不是“垃圾回收” [4]:第 37 行,第 9 列:元素服务器中的预期元素“服务器”而不是“可重新启动” [5]:第 38 行,第 9 列:元素服务器中的预期元素“服务器”而不是“客户端重新连接窗口”

我的tc-config.xml如下:-

<?xml version="1.0" encoding="UTF-8" ?>
<tc:tc-config xmlns:tc="http://www.terracotta.org/config"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-8.xsd">

  <servers>
    <server host="localhost" name="MyServerName">
      <!-- Specify the path where the server should store its data. -->
      <data>E:\Bratton\Pocs\bigmemory-max-4.0.5\data-test</data>
       <!-- Specify the port where the server should listen for client 
       traffic. -->
       <tsa-port>9510</tsa-port>
       <jmx-port>9520</jmx-port>
       <tsa-group-port>9530</tsa-group-port>
       <!-- Enable BigMemory on the server. -->
       <offheap>
         <enabled>true</enabled>
         <maxDataSize>512m</maxDataSize>
       </offheap>
     </server>
    <!-- Add the restartable element for Fast Restartability (optional). -->
    <restartable enabled="true"/>
  </servers>
  <clients>
    <logs>logs-%i</logs>
  </clients>
</tc:tc-config>

下面是ehcache.xml :-

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">
     <terracottaConfig url="localhost:9510"/>
    <defaultCache
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120">
       <terracotta/>    

    </defaultCache>        

</ehcache>

下面是我使用的依赖项

 <dependency> 
                <groupId>net.sf.ehcache</groupId> 
                <artifactId>ehcache-core</artifactId> 
                <version>2.6.0</version> 
            </dependency>

            <dependency>
              <groupId>org.hibernate</groupId>
              <artifactId>hibernate-ehcache</artifactId>
              <version>4.2.4.Final</version>
            </dependency>

            <dependency> 
                <groupId>net.sf.ehcache</groupId> 
                <artifactId>ehcache-terracotta</artifactId> 
                <version>2.6.0</version> 
            </dependency> 

            <dependency> 
                <groupId>org.terracotta</groupId> 
                <artifactId>terracotta-toolkit-runtime-ee</artifactId>
                <version>4.0.5</version> 
            </dependency> 

我尝试了各种依赖版本的组合,但都没用。请让我知道这出了什么问题。

提前感谢。

共有2个答案

楚修为
2023-03-14

hibernate-ehcache依赖于版本早于您指定的ehcache-core。尝试禁用此依赖项,如下所示:

    <dependency> 
        <groupId>org.hibernate</groupId>            
        <artifactId>hibernate-ehcache</artifactId>
        <version>4.2.4.Final</version>
        <exclusions>
            <exclusion>
                <artifactId>ehcache-core</artifactId>
                <groupId>net.sf.ehcache</groupId>
            </exclusion>
        </exclusions>
    </dependency>
公冶渝
2023-03-14

是否尝试使用镜像组标记?有效的配置如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<tc:tc-config xmlns:tc="http://www.terracotta.org/config"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-8.xsd">

  <servers>
    <mirror-group group-name="tsa01">
      <server host="localhost" name="MyServerName">
        <!-- Specify the path where the server should store its data. -->
        <data>E:\Bratton\Pocs\bigmemory-max-4.0.5\data-test</data>
        <!-- Specify the port where the server should listen for client
                traffic. -->
        <tsa-port>9510</tsa-port>
        <jmx-port>9520</jmx-port>
        <tsa-group-port>9530</tsa-group-port>
        <!-- Enable BigMemory on the server. -->
        <offheap>
          <enabled>true</enabled>
          <maxDataSize>512m</maxDataSize>
        </offheap>
      </server>
    </mirror-group>
    <!-- Add the restartable element for Fast Restartability (optional). -->
    <restartable enabled="true"/>
  </servers>
  <clients>
    <logs>logs-%i</logs>
  </clients>
</tc:tc-config>
 类似资料:
  • 我们可以通过下面的简单算法实现该目的: 检查本地缓存的键(key); 如果本地缓存存在该键,则返回它的值; 如果本地缓存不存在该键,则尝试在分布式缓存中找; 如果分布式缓存存在该键,则返回它的值并把它添加到本地缓存; 如果分布式缓存不存在该键,则从数据库中获取,并添加到本地和分布式缓存,最后返回该值。 当在本地缓存服务器中缓存一些信息时,使用这种方式,它还将信息缓存到分布式缓存,但这一次,如果其他

  • 问题内容: 我想在hibernate项目中使用二级缓存,但是我只对hibernate二级缓存了解一点,任何人都可以解释我应该如何在代码中使用它以及需要什么配置和.jar文件吗?我将这些设置设置为我的hibernate.cfg.xml文件 并添加这些jar文件, 我想知道我是否需要更改其他配置? 我怎么知道我的项目使用二级缓存? 如果只是设置此设置,hibernate将自动使用此设置,否则我必须在我

  • Web 应用程序可能需要为成百上千甚至更多的用户同时提供服务。如果你没有采取必要的措施,在这种负载下,你的网站可能会崩溃或变得没有响应。 假设在主页显示最后 10 条新闻,并且平均每分钟有上千名用户访问此页面。你可能为每个用户通过查询数据库来显示页面视图信息: SELECT TOP 10 Title, NewsDate, Subject, Body FROM News ORDER BY NewsD

  • 问题内容: 我正在开发hibernate+ ehcache程序。 ehcache.xml 我在bean.xml中提到了ehcache 我在dao类中的调用方法是 输出为: 但是它在数据库中命中了两次。我在代码中没有发现任何错误。请向我建议为什么它在数据库中命中了两次。 问题答案: 我已经解决了我的问题。我需要添加 在域类中。

  • 我已经将Hazelcast缓存配置为Spring Boot应用程序中的分布式缓存。 我想要为同一实例提供本地缓存,其中很少缓存不应共享。 如何在应用中一起做本地和分布式缓存?

  • 问题内容: 我正在寻找Java分布式缓存解决方案。我们希望功能喜欢: 我们已经分析了Terracotta这样的框架,它似乎是缓存框架中我们想要的一切……但是,似乎需要一个中央缓存节点,这成为我们的单点故障。 除了推出我们自己的解决方案之外,还有其他想法吗? 问题答案: 我建议使用JBossCache或EhCache(使用分布式缓存侦听器)。我都用过,我都喜欢,它们都适合您的要求。