JIRA问题事件监听器

时间:2016-12-01 12:58:54

标签: java jira jira-plugin

我正在尝试使用tutorial创建一个JIRA Listener,但是教程已经过时,我遇到了一个问题。插件构建,安装,但当我想注册Listener我正在

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

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

1 个答案:

答案 0 :(得分:0)

最近的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 注释添加到您的侦听器类;
  • 您的课程应该实施 InitializingBean DisposableBean LifecycleAware 接口;
  • 覆盖 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) {
        ...
    }

    ...

}

希望这有帮助!