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

如何在TomEE Plume 10.0.1中通过tomee.xml配置MicroProfile解决注入问题

解决TomEE Plume 10.0.1中MetricRegistry与ConfigProperty注入失败问题

问题根源

TomEE 10基于Jakarta EE 9.1,默认未自动激活MicroProfile Config和Metrics的CDI扩展,导致MetricRegistry和@ConfigProperty找不到默认提供者,必须通过tomee.xml显式开启相关扩展。

tomee.xml配置方案

方式1:针对CDI容器精准配置

在tomee.xml的<tomee>根节点内添加CDI容器配置,按需启用所需扩展:

<Container id="cdi-container" type="Cdi">
  <!-- 开启MicroProfile Config支持 -->
  <Property name="mpConfigEnabled">true</Property>
  <!-- 开启MicroProfile Metrics支持 -->
  <Property name="mpMetricsEnabled">true</Property>
</Container>

方式2:全局简洁配置

如果需要全局启用所有MicroProfile相关扩展,直接在<tomee>节点下添加全局属性:

<Property name="mp.config.enabled">true</Property>
<Property name="mp.metrics.enabled">true</Property>

验证步骤

配置完成后重启TomEE:

  • 测试@Inject MetricRegistry registry是否能正常注入,不存在"无默认提供者"报错
  • 测试@Inject @ConfigProperty(name = "your.config.key") String configVal是否能正确读取配置值

额外注意事项

  • TomEE Plume版本已自带MicroProfile Config和Metrics的API依赖,无需在项目构建文件(pom.xml/build.gradle)中额外引入
  • 若之前通过代码层面(如修改beans.xml、添加扩展类)解决过该问题,建议移除相关代码,避免配置冲突

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 14:24:54