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

Spring Boot集成Infinispan启动失败:无法获取文件系统锁求助

问题:Spring Boot + Infinispan 二次启动锁冲突异常

错误现象

应用首次启动无异常,二次启动时抛出锁获取失败错误:

Caused by: org.infinispan.manager.EmbeddedCacheManagerStartupException: ISPN029025: Failed acquiring lock 'FileSystemLock{directory=.\cache1\0\RT12-CACHE, file=RT12-CACHE.lck}' for SIFS
at org.infinispan.manager.DefaultCacheManager.internalStart(DefaultCacheManager.java:781)
at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:746)
at org.infinispan.manager.DefaultCacheManager.(DefaultCacheManager.java:412)
at org.infinispan.manager.DefaultCacheManager.(DefaultCacheManager.java:361)
at org.infinispan.manager.DefaultCacheManager.(DefaultCacheManager.java:336)
at org.infinispan.manager.DefaultCacheManager.(DefaultCacheManager.java:324)

现有缓存配置

使用的local-cache-configuration片段:

<local-cache-configuration name="default-template-1" statistics="true">
    <expiration lifespan="129600000"/>
    <persistence>
        <file-store path="./cache1/1"/>
    </persistence>
</local-cache-configuration>

<local-cache-configuration name="template-no-cache" statistics="true">
    <expiration lifespan="0"/>
    <persistence>
        <file-store path="./cache1/0"/>
    </persistence>
</local-cache-configuration>

<local-cache-configuration name="template-60-min-cache" statistics="true">
    <expiration lifespan="3600000"/>
    <persistence>
        <file-store path="./cache1/0"/>
    </persistence>
</local-cache-configuration>

<local-cache-configuration name="template-1-min-cache" statistics="true">
    <expiration lifespan="60000"/>
    <persistence>
        <file-store path="./cache1/0"/>
    </persistence>
</local-cache-configuration>

<local-cache-configuration name="template-10-min-cache" statistics="true">
    <expiration lifespan="600000"/>
    <persistence>
        <file-store path="./cache1/0"/>
    </persistence>
</local-cache-configuration>

<local-cache-configuration name="template-20-sec-cache" statistics="true">
    <expiration lifespan="20000"/>
    <persistence>
        <file-store path="./cache1/1"/>
    </persistence>
</local-cache-configuration>

<local-cache-configuration name="template-cm-3" statistics="true">
    <!--            for 60 minutes-->
    <expiration lifespan="3600000"/>
    <persistence>
        <file-store path="./cache1/1"/>
    </persistence>
</local-cache-configuration>

版本信息

  • Spring Boot 3.2.2
  • infinispan-spring-boot-starter-embedded 14.0.28.Final
  • infinispan-core 15.0.3.Final

解决方案

1. 修复缓存目录冲突(核心解决办法)

多个缓存模板共享了同一个file-store路径(如./cache1/0被4个模板复用),Infinispan会为每个缓存的存储目录加锁,共享目录会导致锁竞争,启动时无法获取锁。

给每个缓存模板分配独立的存储路径,示例:

<local-cache-configuration name="template-no-cache" statistics="true">
    <expiration lifespan="0"/>
    <persistence>
        <file-store path="./cache1/template-no-cache"/>
    </persistence>
</local-cache-configuration>

<local-cache-configuration name="template-60-min-cache" statistics="true">
    <expiration lifespan="3600000"/>
    <persistence>
        <file-store path="./cache1/template-60-min-cache"/>
    </persistence>
</local-cache-configuration>

2. 开发环境临时优化

如果是开发调试场景,可通过配置避免锁残留:

  • 添加锁超时时间,超时后强制尝试获取锁:
<file-store path="./cache1/0" lock-timeout="30000"/>
  • 开启启动时清理存储目录(生产环境禁用,会丢失缓存数据):
<file-store path="./cache1/0" purge-on-startup="true"/>

3. 确保应用优雅关闭

锁残留可能源于上次关闭时未正常释放锁:

  • 检查Spring配置中EmbeddedCacheManager的销毁回调,Spring Boot Infinispan Starter默认会处理,也可手动指定:
@Bean(destroyMethod = "stop")
public EmbeddedCacheManager infinispanCacheManager() {
    return new DefaultCacheManager("infinispan.xml");
}
  • 在IDEA中停止应用时,使用Stop按钮而非强制终止,避免进程残留。

4. 统一版本兼容性

当前infinispan-spring-boot-starter-embedded(14.x)和infinispan-core(15.x)跨大版本,可能存在兼容性问题,建议将infinispan-core版本降级到14.0.28.Final,与starter版本保持一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 11:05:55