Hi,
I'm trying to run the example of a Crowd plugin with Event Listeners but it does not work.
I see differences between the official documentation and the repository example. For example, in the repository there is no listener section in atlassian-plugin.xml.
I have replaced the "System.out.println" line with a slf4j logger, but it also does not print any logs when a user is created.
If I add the listener section in atlassian-plugin.xml, when I launch Crowd it returns an error of ClassNotFoundException:
2022-06-16 09:48:53,336 localhost-startStop-1 ERROR [atlassian.plugin.manager.DefaultPluginManager] There was an error loading the descriptor 'User Created Listener' of plugin 'com.atlassian.crowd.example.crowd-event-listener-example'. Disabling.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.atlassian.crowd.event.listener.example.UserCreatedListener': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.atlassian.crowd.event.listener.example.UserCreatedListener] from ClassLoader [com.atlassian.crowd.example.crowd-event-listener-example [28]]
at com.atlassian.crowd.console.listener.StartupListener.contextInitialized(StartupListener.java:101)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4705)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.atlassian.crowd.event.listener.example.UserCreatedListener] from ClassLoader [com.atlassian.crowd.example.crowd-event-listener-example [28]]
Caused by: java.lang.ClassNotFoundException: com.atlassian.crowd.event.user.UserCreatedEvent not found by com.atlassian.crowd.example.crowd-event-listener-example [28]
This is the source code (without the listener section):
UserCreatedListener.java
package com.atlassian.crowd.event.listener.example;
import com.atlassian.crowd.event.user.UserCreatedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UserCreatedListener{
private static final Logger log = LoggerFactory.getLogger(UserCreatedListener.class);
@com.atlassian.event.api.EventListener
public void printUserCreatedEvent(UserCreatedEvent event) {
log.debug("User " + event.getUser().getDisplayName() + " has been created.");
}
}
atlassian-plugin.xml
<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}" />
</plugin-info>
</atlassian-plugin>pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.atlassian.crowd.event.listener.example</groupId>
<artifactId>crowd-event-listener-example</artifactId>
<version>1.0.1-SNAPSHOT</version>
<organization>
<name>Example Company</name>
<url>http://www.example.com/</url>
</organization>
<name>event-listener-example</name>
<description>This is an event listener plugin for Atlassian Crowd.</description>
<packaging>atlassian-plugin</packaging>
<repositories>
<repository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/mvn/maven-external/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/mvn/maven-external/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.atlassian.crowd</groupId>
<artifactId>crowd-events</artifactId>
<version>${crowd.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.event</groupId>
<artifactId>atlassian-event</artifactId>
<version>4.1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>crowd-maven-plugin</artifactId>
<version>8.2.3</version>
<extensions>true</extensions>
<configuration>
<productVersion>${crowd.version}</productVersion>
<productDataVersion>${crowd.data.version}</productDataVersion>
<enableQuickReload>true</enableQuickReload>
<instructions>
<Import-Package>
com.atlassian.event.*
</Import-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<crowd.version>4.3.5</crowd.version>
<crowd.data.version>4.1.10</crowd.data.version>
</properties>
</project>
Thanks!