Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApplicationEvents with generic type argument do not get published to listener using Spring 4.2 [DATAKV-116] #94

Open
spring-projects-issues opened this issue Oct 15, 2015 · 0 comments
Assignees
Labels
in: core Issues in core support type: bug A general bug

Comments

@spring-projects-issues
Copy link

Christoph Strobl opened DATAKV-116 and commented

Type reolution fails for ApplicationEvents using generic types. Using Spring 4.2 it is required to either implement ResolvableTypeProvider or extend PayloadApplicationEvent. In order to support 4.2 from a 4.1 based source we need to provide means to deal with this by providing base handling the generics.

class KeyValueEventListener <E> implements ApplicationListener<KeyValueEvent<?>> {

	private final Class<?> domainClass;

	public KeyValueEventListener() {
		Class<?> typeArgument = GenericTypeResolver.resolveTypeArgument(this.getClass(), NeoEventListener.class);
		this.domainClass = typeArgument == null ? Object.class : typeArgument;
	}

	@SuppressWarnings({ "unchecked" })
	public void onApplicationEvent(KeyValueEvent<?> event) {

		if (event instanceof BeforeDeleteEvent<?>) {
			BeforeDeleteEvent<?> beforeDeleteEvent = (BeforeDeleteEvent<?>) event;

			// inspect for matching types and ignore others
			if (domainClass.isAssignableFrom(beforeDeleteEvent.getType())) {
				onBeforeDelete((BeforeDeleteEvent <E>) event);
			}
			// other event types...

		}
	}

	protected void onBeforeDelete(BeforeDeleteEvent<E> event) {

	}
}

Affects: 1.0 GA (Gosling)

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core support labels Dec 31, 2020
@jxblum jxblum changed the title ApplicationEvents with generic type argument do not get published to listener using Spring 4.2. [DATAKV-116] ApplicationEvents with generic type argument do not get published to listener using Spring 4.2 [DATAKV-116] Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants