I have a scenario to create a bean lazily. The class annotation with @EventListener. The object was created, but it didn't listen to any event. I had to change the class to implement EventListener.

I have created one small project to demonstrate the issue. There are two tests where one eagerly creates a bean, and the other one creates lazily. The failing one shows the bean doesn't have the point cut of @EventListener annotation. I used other types of annotation (e.g. @Cacheable) bean-with-annotation.zip , but the effect was the same.

Comment From: snicoll

The arrangement is a bit weird, isn't it? If we fixed this issue to register the listener lazily, then your component would start listening to the chosen events, but only once "something" triggers the creation of the target bean.

We do loop over all beans after singletons are instantiated to register event listeners, if any. But we avoid doing so on lazy bean as it would defeat the purpose of making them as such. Your analogy with @Cacheable is incorrect as the operation is invoked on the method itself and doesn't depend on an external component doing something (publishing an event).

I can see how this could be more prominent in the documentation, though.