0
votes

I'm trying to make a JIRA Listener with tutorial but the tutorial is outdate and I've encoutered a problem. Plugin builds, installs but when I want to register Listener I'm getting

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

I'm trying to do this on JIRA 6.4.13 but tutorial on JIRA 7.x would be also apprieciated.

1

1 Answers

0
votes

recent Jira versions uses Spring Scanner as described at https://bitbucket.org/atlassian/atlassian-spring-scanner. Generally, you should:

  • in pom.xml add provided dependency for atlassian-spring-scanner-annotation
  • create a Spring XML file in src/main/resources/META-INF/spring/;
  • remove any component-import from atlassian-plugin.xml;
  • instead of removed component-import, add @Component annotation to your listener class;
  • you class should implement InitializingBean, DisposableBean and LifecycleAware interfaces;
  • overide afterPropertiesSet() to register your listener.

So, your code should looks like this

@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) {
        ...
    }

    ...

}

Hope this helps!