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

在Ehcache 3.8.10中启用JMX指标遇Jsr107Service工厂缺失错误

解决Ehcache 3.8.10启用JMX指标时的Jsr107Service缺失异常

错误原因

你遇到的No factories exist for interface org.ehcache.jsr107.Jsr107Service异常,本质是类路径中缺少Ehcache JSR107(JCache)支持模块。Ehcache 3将JSR107相关功能从核心包中拆分出来,单独作为一个依赖模块,仅引入核心包的话无法加载JSR107服务工厂。

解决方案

1. 添加JSR107依赖

根据你的项目构建工具,添加对应版本的Ehcache JSR107依赖:

Maven项目

在pom.xml中加入:

<dependency>
    <groupId>org.ehcache</groupId>
    <artifactId>ehcache-jcache</artifactId>
    <version>3.8.10</version>
</dependency>

Gradle项目

在build.gradle中加入:

implementation 'org.ehcache:ehcache-jcache:3.8.10'

2. 修正XML配置的Schema Location

你的XML配置中已经引入了jsr107命名空间,但xsi:schemaLocation未包含JSR107对应的Schema地址,需要补充完整:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.ehcache.org/v3"
        xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
        xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd
                            http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107.xsd" >

    <service>
        <jsr107:defaults enable-management="true" enable-statistics="true"/>
    </service>

    <cache alias="authprovidercache">
        <key-type>java.lang.Object</key-type>
        <value-type>java.lang.Object</value-type>
        <expiry>
            <ttl>360</ttl>
        </expiry>
        <resources>
            <heap unit="entries">1000</heap>
        </resources>
    </cache>

</config>

3. 验证配置

主程序代码无需修改,重新构建并运行后,JMX指标应该可以正常启用。你可以通过JConsole或其他JMX工具连接到程序,查看Ehcache的管理和统计指标。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 13:46:18