-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
EventListenerMethodProcessor causes expensive introspection of lazy beans #22293
Comments
There are a number of candidates that would do that sort of things. ping @jhoeller |
The simple fix would be |
Same here! Our application loaded 20, 000 extra classes because of getDeclaredMethod of lazy beans. We saved about 40 seconds by skipping lazy bean here. |
Reviewing this from a 6.2 perspective and experimenting with the effects in a common scenarios, I am not convinced that a change in To reliably avoid eager initialization of a As for expensive reflection steps, we cache declared methods etc, so this should be reasonably efficient for beans that have been introspected before. However, for a lazy-init bean class not seen before at all, we would initiate reflection there indeed. How this could arrive at 20000 extra classes, I have no idea... If there are so many lazy beans with so many different classes involved, I would seriously slice the application's configuration to what is actually needed, instead of apparently defining lots of unnecessary beans which will never get used in the current run. Lazy beans are meant to be used selectively for certain use cases, mostly around rarely used application functionality that is only to be initialized when actually requested. Even there, warming up such lazy classes upfront can be seen as part of the container's startup measures; it's instantiation that is lazy, not introspection of the class. |
Affects: 5.1.4
I was attempting to fix spring-projects/spring-amqp#885 to avoid eager initialization of a lazy factory bean as reported in the linked Stack Overflow question.
After fixing it, I found the FB is still instantiated, but by the
EventListenerMethodProcessor
instead...spring-framework/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java
Lines 100 to 103 in 155ef5f
The text was updated successfully, but these errors were encountered: