You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Infinispan本地缓存环境下禁用JGroups

问题

将Infinispan版本从org.infinispan.hibernate.cache.v53升级至6.2,且应用改为Spring Boot启动后,JGroups被自动启动。由于应用无需与其他进程共享缓存,希望禁用JGroups,但使用SampleCacheManager仍出现JGroups相关日志,生产环境中多个独立进程会导致JGroups尝试连接超时。

相关日志

11/17 11:27:35.269 DEBUG                 main         org.infinispan.manager.DefaultCacheManager - Starting cache manager SampleCacheManager
11/17 11:27:36.349 WARN                  main                     org.jgroups.stack.Configurator - JGRP000014: ThreadPool.thread_dumps_threshold has been deprecated: ignored
11/17 10:09:39.464 DEBUG                 main                          org.jgroups.protocols.TCP - thread pool min/max/keep-alive (ms): 0/200/60000
...

当前Infinispan配置

<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns="urn:infinispan:config:15.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:infinispan:config:15.0 http://www.infinispan.org/schemas/infinispan-config-15.0.xsd">

        <!-- 适用于单实例访问DB的非集群环境 -->
        <cache-container name="SampleCacheManager" default-cache="the-default-cache" shutdown-hook="DEFAULT">
            <local-cache-configuration name="the-default-cache"  />
            
            <!-- 适用于实体/集合缓存的默认配置 -->
            <local-cache-configuration name="entity-cache" simple-cache="true" >
                <expiration max-idle="3600000" interval="5000"/>
                <memory max-count="10000" />
            </local-cache-configuration>
            
            <local-cache-configuration name="collections-cache" simple-cache="true" >
                <expiration max-idle="3600000" interval="5000"/>
                <memory max-count="100000" />
            </local-cache-configuration>
            
            <!-- 查询缓存配置,不复制查询结果 -->
            <local-cache-configuration name="local-query" simple-cache="true" >
                <expiration max-idle="3600000" interval="5000"/>
                <memory max-count="10000" />
            </local-cache-configuration>
            
            <local-cache-configuration name="timestamps" simple-cache="true" >
                <locking concurrency-level="1000" acquire-timeout="15000"/>
                <expiration interval="0"/>
                <!-- 永不驱逐修改时间戳 -->
                <memory when-full="NONE"/>
            </local-cache-configuration>
            
            <!-- 自定义缓存配置:本地非事务型,设置过期时间避免内存泄漏,优化性能 -->
            <local-cache-configuration name="pending-puts" simple-cache="true" >
                <expiration max-idle="3600000" />
            </local-cache-configuration>
        </cache-container>
    </infinispan>

禁用JGroups的方法

1. 修改Infinispan核心配置

在cache-container标签中添加cluster="none"属性,显式禁用集群模式,从根源上阻止JGroups初始化:

<cache-container name="SampleCacheManager" default-cache="the-default-cache" shutdown-hook="DEFAULT" cluster="none">

该配置会让Infinispan完全以本地模式运行,不会加载任何集群相关组件。

2. 排除JGroups依赖

如果希望彻底移除JGroups的jar包,避免不必要的类加载,在构建工具中排除JGroups依赖:

  • Maven:
<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-hibernate-cache-v62</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.jgroups</groupId>
            <artifactId>jgroups</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  • Gradle:
implementation('org.infinispan:infinispan-hibernate-cache-v62') {
    exclude group: 'org.jgroups', module: 'jgroups'
}

3. 配置Spring Boot自动开关

利用Spring Boot的自动配置属性,直接关闭Infinispan集群功能:

  • application.properties:
spring.infinispan.cluster.enabled=false
  • application.yml:
spring:
  infinispan:
    cluster:
      enabled: false

以上三种方法可单独使用,也可组合使用,确保JGroups完全不会被启动,解决生产环境中的连接超时问题。

内容的提问来源于stack exchange,提问作者Pichou Bichou

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 00:34:59