【问题标题】:JIRA Issue Event ListenerJIRA 问题事件监听器
【发布时间】:2016-12-01 12:58:53
【问题描述】:

我正在尝试使用 tutorial 创建一个 JIRA 侦听器,但该教程已过时并且我遇到了一个问题。插件构建,安装,但是当我想注册监听器时,我得到了

Class [com.example.tutorial.plugins.IssueCreatedResolvedListener] is not of type JiraListener.

我正在尝试在 JIRA 6.4.13 上执行此操作,但也适用于 JIRA 7.x 的教程。

【问题讨论】:

    标签: java jira jira-plugin


    【解决方案1】:

    最近的 Jira 版本使用 https://bitbucket.org/atlassian/atlassian-spring-scanner 中所述的 Spring Scanner。一般来说,你应该:

    • pom.xml 中为 atlassian-spring-scanner-annotation 添加提供的依赖项
    • src/main/resources/META-INF/spring/中创建一个Spring XML文件
    • atlassian-plugin.xml 中删除任何 component-import
    • 不要移除 component-import,而是将 @Component 注释添加到您的侦听器类;
    • 你的类应该实现InitializingBeanDisposableBeanLifecycleAware接口;
    • 覆盖 afterPropertiesSet() 以注册您的监听器。

    所以,你的代码应该是这样的

    @ExportAsService
    @Component
    @Named("IssueCreatedResolvedListener")
    public class IssueCreatedResolvedListener implements InitializingBean, DisposableBean, LifecycleAware {
        @ComponentImport
        private final ApplicationProperties applicationProperties;
        @ComponentImport
        private final EventPublisher eventPublisher;
        @ComponentImport
        protected final LifecycleManager lifecycleManager;
    
        @Inject
        public IssueCreatedResolvedListener(final ApplicationProperties applicationProperties, final EventPublisher eventPublisher,
            final LifecycleManager lifecycleManager) {
            this.applicationProperties = applicationProperties;
            this.eventPublisher = eventPublisher;
            this.lifecycleManager = lifecycleManager;
        }
    
        @Override
        public void afterPropertiesSet() {
            eventPublisher.register(this);
        }
    
        @EventListener
        public void onIssueEvent(IssueEvent issueEvent) {
            ...
        }
    
        ...
    
    }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2016-08-26
      • 2010-11-16
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2014-02-21
      相关资源
      最近更新 更多