You should create a a component which implements InitializingBean and add the registration to the afterPropertiesSet to make sure it is executed once the bean has been initialised (which is a good way to know for sure Jira is ready).
Semi-pseudo code:
public class EventListener implements InitializingBean {
public EventListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@Override
public void afterPropertiesSet() throws Exception {
// Register ourselves with the EventPublisher
eventPublisher.register(this);
}
@Override
public void destroy() throws Exception {
// Unregister ourselves with the EventPublisher
eventPublisher.unregister(this);
}
}
Yes I did try the other usual listener route as well like you would if you are writing a event listener for Issue events.
This is the confusing part for me.
I have 3, Issue,Groups and Project. First 2 absolutely no issues they just work. Project event listener just simply does not what it says on the tin no matter what route I follow.
@Scanned
@Component
public class ProjectEventListener implements InitializingBean, DisposableBean {
private final EventPublisher eventPublisher;
@Inject
public ProjectEventListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@Override
public void afterPropertiesSet() throws Exception {
eventPublisher.register(this);
}
@Override
public void destroy() throws Exception {
eventPublisher.unregister(this);
}
@EventListener
public void onProjectDeletedEvent(ProjectDeletedEvent projectDeletedEvent) {
System.out.println("project deleted" + projectDeletedEvent);
}
}
@Component seems to be the missing link
Strangely I don’t need that for a Listener that is listening to events related to Group updates no idea why this one needs it … yay but its working now
@i0in.ltd yeah I was wondering if I need to further explain the “You should create a a component” part of my comment
For some reason, the listener that is listening to events related to Group is picked up by the Spring scanner. Or maybe you have added it as <component /> to the atlassian-plugin.xml?