我正在使用camel 2.18.1 和camel-ehcache 组件来构建一个简单的缓存。虽然缓存设置工作正常,但我发现使用 ehcache 3.1.2 注册 mbean 很困难(这是通过骆驼拉入的)。
阅读文档 - 目前尚不清楚如何启用对 3.x 的支持,因为 API 上不再提供使用 ManagementService 注册 mbean 的标准方式。
该文档与纯 ehcache 实现和 JSR-107 缓存实现有点混淆。
尽管 JSR-107 JCache 实现具有打开 JMX 支持的选项,但连接 xml 配置并启动缓存看起来会在缓存启动时引发异常:
Caused by: java.lang.IllegalArgumentException: Couldn't resolve Service org.ehcache.jsr107.config.Jsr107Service
我的 xml 配置供参考如下:关于如何启用对 ehcache 3.x 的 JMX 支持以及需要哪些额外依赖项的任何指针?
<ehcache:config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:ehcache="http://www.ehcache.org/v3"
xmlns:jcache="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<ehcache:service>
<jcache:defaults jsr-107-compliant-atomics="true" enable-management="true" enable-statistics="true">
<jcache:cache name="my-cache" template="myDefaultTemplate"/>
</jcache:defaults>
</ehcache:service>
<ehcache:persistence directory="/var/cache"/>
<ehcache:cache alias="cache-test">
<!--
OPTIONAL, defaults to no expiry
Entries to the Cache can be made to expire after a given time
-->
<ehcache:expiry>
<!--
time to idle, the maximum time for an entry to remain untouched
Entries to the Cache can be made to expire after a given time
other options are:
* <ttl>, time to live;
* <class>, for a custom Expiry implementation; or
* <none>, for no expiry
-->
<ehcache:tti unit="minutes">2</ehcache:tti>
</ehcache:expiry>
<!--
The maximal number of entries to be held in the Cache, prior to eviction starting
-->
<ehcache:heap unit="entries">200</ehcache:heap>
<!--
OPTIONAL
Any further elements in another namespace
-->
<jcache:mbeans enable-statistics="true" enable-management="true" />
</ehcache:cache>
<!--
OPTIONAL
A <cache-template> defines a named template that can be used be <cache> definitions in this same file
They have all the same property as the <cache> elements above
-->
<ehcache:cache-template name="myDefaultTemplate">
<ehcache:expiry>
<ehcache:none/>
</ehcache:expiry>
<!--
OPTIONAL
Any further elements in another namespace
-->
</ehcache:cache-template>
</ehcache:config>