spring-framework: `ApplicationListener` no longer invoked for generic `ApplicationEvent` with 6.2.0
Hello!
I have simple interface like this:
public interface ITest
{
}
and the simple event:
public class TestEvent<T extends ITest> extends ApplicationEvent
{
public TestEvent(Object source)
{
super(source);
}
}
and two listeners:
@Component
public class MethodListener
{
@EventListener
public void handleTestEvent(TestEvent<ITest> iTest)
{
System.out.println(this.getClass() + " DONE!");
}
}
@Component
public class SimpleTestListener implements ApplicationListener<TestEvent<ITest>>
{
@Override
public void onApplicationEvent(TestEvent<ITest> event)
{
System.out.println(this.getClass() + " DONE!");
}
}
and when i trying to send an event via the spring context like this:
public class MySpringApplication
{
public static void main(String[] args)
{
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
context.publishEvent(new TestEvent<>(""));
}
}
i have different result in depends on the version Spring. When i use Spring 6.2 i can see in the log this:
class ... MethodListener DONE!
when i use Spring 6.1.15 i see both results:
class ...SimpleTestListener DONE!
class ...MethodListener DONE!
I guess it’s a bug.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 15 (8 by maintainers)
Commits related to this issue
- Restore lenient match against unresolvable wildcard Closes gh-33982 — committed to spring-projects/spring-framework by jhoeller 2 years ago
- Unit test for match against unresolvable wildcard See gh-33982 — committed to spring-projects/spring-framework by jhoeller 2 years ago
This turned out to be rather involved, a consequence of the partial generics matching that we do as of 6.2 now where we also take the bounds of an unresolvable type variable into account. The solution that I went with is a rather minimal tweaking of the existing
strictflag when we go into nested generics. I hope that this covers the reported case here. @denAbramoff please give an upcoming 6.2.1 snapshot an early try…@anaconda875 I ended up with a different approach but thanks for the PR in any case!
Probably related to #33968.
@sbrannen thanks for your reaction! Yep, this version works:
But it’s not convenient and there are a lot of places where old version works.
And there is also one weird case, if i add “? extends” my listenerer will work:
It works on Spring 6.2!
class …WildcardSimpleTestListener$$SpringCGLIB$$0 DONE!