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

Jira插件注入TemporaryAttachmentsMonitorLocator提示无匹配Bean报错

问题根因

TemporaryAttachmentsMonitorLocator注入失败的核心原因是该服务的暴露逻辑和你插件的OSGi依赖配置不匹配:

  • 低于Jira 8.0的版本中,该类不属于Jira核心API导出的服务,由Jira原生导入插件(JIM)单独暴露,@ComponentImport默认只会扫描Jira核心bundle导出的服务,无法识别其他插件暴露的服务
  • 高版本Jira中如果出现该报错,通常是你本地的jira-api依赖版本和测试环境的Jira版本不一致,或是OSGi导入声明缺失
  • 低版本atlassian-spring-scanner不支持跨插件的注解式服务导入
修复方案

方案1:适配低版本Jira(<8.0)

  1. 在pom.xml中添加JIM插件依赖,scope设为provided
<dependency>
  <groupId>com.atlassian.jira.plugins</groupId>
  <artifactId>jira-import-plugin</artifactId>
  <version>匹配你目标Jira版本的JIM版本号</version>
  <scope>provided</scope>
</dependency>
  1. 在atlassian-plugin.xml中显式声明服务导入,替代注解式导入
<component-import key="temporaryAttachmentsMonitorLocator" interface="com.atlassian.jira.issue.TemporaryAttachmentsMonitorLocator" />
  1. 移除构造方法中该参数的@ComponentImport注解即可

方案2:适配高版本Jira(≥8.0)

  1. 检查pom.xml中jira-api的依赖版本是否和测试环境Jira版本完全一致,scope保持为provided
  2. 升级atlassian-spring-scanner依赖到2.1.7及以上版本,兼容跨bundle的注解式服务导入
  3. 清理插件构建缓存,重新打包部署即可

方案3:动态获取服务(兼容所有版本)

如果不想处理版本兼容问题,可以直接通过OSGi上下文动态获取服务,无需提前声明导入:

public class TrelloSetupPage extends AbstractSetupPage {
    private final TemporaryAttachmentsMonitorLocator locator;

    public TrelloSetupPage(@ComponentImport UsageTrackingService usageTrackingService, 
                           @ComponentImport WebInterfaceManager webInterfaceManager,
                           @ComponentImport PluginAccessor pluginAccessor, 
                           @ComponentImport EventPublisher eventPublisher,
                           @ComponentImport OsgiContainerManager osgiContainerManager) {
        super(usageTrackingService, webInterfaceManager, pluginAccessor, eventPublisher);
        // 动态获取目标服务
        BundleContext bundleContext = osgiContainerManager.getBundleContext();
        ServiceReference<TemporaryAttachmentsMonitorLocator> serviceRef = bundleContext.getServiceReference(TemporaryAttachmentsMonitorLocator.class);
        this.locator = bundleContext.getService(serviceRef);
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 21:39:02