Hello,I have tried many ways to create and event listener for the 'issue create event'.
onIssueEvent() it does not get called.Here's my code:Any suggestion or help?thanks,George Nistor
package com.infineon.plugin.listeners;import com.atlassian.event.api.EventListener;import com.atlassian.event.api.EventPublisher;import com.atlassian.jira.event.issue.IssueEvent;import com.atlassian.jira.event.type.EventType;import com.atlassian.jira.issue.Issue;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import javax.annotation.PostConstruct;import javax.annotation.PreDestroy;import javax.inject.Inject;import javax.inject.Named;@Namedpublic class IssueCreateEventListener {private static final Logger log = LoggerFactory.getLogger(IssueCreateEventListener.class);private final EventPublisher eventPublisher;@Injectpublic IssueCreateEventListener(EventPublisher eventPublisher) {this.eventPublisher = eventPublisher; }@PostConstructpublic void init() { eventPublisher.register(this); }@PreDestroypublic void cleanup() { eventPublisher.unregister(this); }@EventListenerpublic void onIssueEvent(IssueEvent issueEvent) { System.out.println("Received event: " + issueEvent.getEventTypeId());if (EventType.ISSUE_CREATED_ID.equals(issueEvent.getEventTypeId())) { Issue issue = issueEvent.getIssue();if (issue != null) { log.warn("New issue created: {} - {}", issue.getKey(), issue.getSummary()); } else { log.error("Received ISSUE_CREATED event, but Issue is null."); } } }}
Hi @George Nistor
The listener code seems structurally correct. If onIssueEvent is not being triggered, and as far as I see you use annotation-based scanning, you need to ensure that it's being scanned correctly. Check that the class is part of a package under the scanned component-scan base package, in spring-scanner settings. You can also manually register it in the atlasian-plugin.xml
<component key="issue-create-listener" class="com.infineon.plugin.listeners.IssueCreateEventListener"/>
Checking the logs will also give some clues, your plugin may not have loaded successfully meaning that during the startup it may have failed. So, check the JIRA_HOME/log/atlassian-jira.log file and see if there are any errors related to the plugin.
It is solved!I created this class in config folder:
package com.infineon.plugin.config;import com.atlassian.event.api.EventPublisher;import com.atlassian.jira.component.ComponentAccessor;import com.atlassian.jira.issue.IssueManager;import com.atlassian.jira.project.ProjectManager;import com.atlassian.jira.user.util.UserManager;import com.atlassian.jira.security.JiraAuthenticationContext;import com.atlassian.jira.bc.user.search.UserSearchService;import com.atlassian.cache.CacheManager;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Scope;@Configuration@ComponentScan(basePackages = {"com.infineon.plugin.events","com.infineon.plugin.rest",})public class PluginConfiguration {/** * JIRA Issue Manager Bean * Provides access to JIRA's issue management functionality */ @Bean @Scope("singleton")public IssueManager issueManager() {return ComponentAccessor.getIssueManager(); }/** * JIRA Project Manager Bean * Provides access to JIRA's project management functionality */ @Bean @Scope("singleton")public ProjectManager projectManager() {return ComponentAccessor.getProjectManager(); }/** * JIRA User Manager Bean (correct for JIRA 9.x) * Provides access to JIRA's user management functionality */ @Bean @Scope("singleton")public UserManager userManager() {return ComponentAccessor.getUserManager(); }/** * JIRA User Search Service Bean * Provides user search functionality */ @Bean @Scope("singleton")public UserSearchService userSearchService() {return ComponentAccessor.getComponent(UserSearchService.class); }/** * JIRA Authentication Context Bean * Provides access to current user context */ @Bean @Scope("singleton")public JiraAuthenticationContext authenticationContext() {return ComponentAccessor.getJiraAuthenticationContext(); }/** * Cache Manager Bean * Get CacheManager using ComponentAccessor.getComponent() */ @Bean @Scope("singleton")public CacheManager cacheManager() {return ComponentAccessor.getComponent(CacheManager.class); }/** * Plugin Properties Bean * Configuration properties for the plugin */ @Bean @Scope("singleton")public PluginProperties pluginProperties() {return new PluginProperties(); }/** * Custom configuration properties class */ public static class PluginProperties {private String defaultTagColor = "#007cbb";private int maxTagsPerIssue = 10;private boolean enableAutoTagging = true;public String getDefaultTagColor() {return defaultTagColor; }public void setDefaultTagColor(String defaultTagColor) {this.defaultTagColor = defaultTagColor; }public int getMaxTagsPerIssue() {return maxTagsPerIssue; }public void setMaxTagsPerIssue(int maxTagsPerIssue) {this.maxTagsPerIssue = maxTagsPerIssue; }public boolean isEnableAutoTagging() {return enableAutoTagging; }public void setEnableAutoTagging(boolean enableAutoTagging) {this.enableAutoTagging = enableAutoTagging; } }@Bean @Scope("singleton")public EventPublisher eventPublisher() {return ComponentAccessor.getComponent(EventPublisher.class); }}
It still does not work.Can you provide more tips, how do I need to change more.
I added "@Component" to my IssueCreatedEventListener classI added this section in pom.xml:
<plugin> <groupId>com.atlassian.plugin</groupId> <artifactId>atlassian-spring-scanner-maven-plugin</artifactId> <version>2.2.5</version> <executions> <execution> <goals> <goal>atlassian-spring-scanner</goal> </goals> <phase>process-classes</phase> </execution> </executions> <configuration> <scannedDependencies> <dependency> <groupId>com.atlassian.plugin</groupId> <artifactId>atlassian-spring-scanner-external-jar</artifactId> </dependency> </scannedDependencies> <verbose>false</verbose> </configuration> </plugin></plugins>
I tried also to add:
<context:component-scan base-package="com.infineon.plugin.listeners" />
in plugin-context.xmlbut my plugin does not start anymore!
Hi,
Don't use the <component-scan> in plugin-context.xml with the Atlassian Spring scanner together. They are alternatives, sorry if I was misunderstood.
So, remove the context:component-scan from the plugin-context.xml file.
In your pom.xml add these dependencies
<dependencies> <dependency> <groupId>com.atlassian.plugin</groupId> <artifactId>atlassian-spring-scanner-annotation</artifactId> <version>2.2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.plugin</groupId> <artifactId>atlassian-spring-scanner-runtime</artifactId> <version>2.2.5</version> </dependency></dependencies>
And the plugin section you've mentioned above looks good.
This way, there is no need to add to atlassian-plugin.xml.
run the cli command atlas-clean ant then atlas-run
Then check the atlassian-jira.log file. If you have any error logs, share them here.
It looks like you're new here. Sign in or register to get started.