Can someone give a real case example of how using boolean element proxyBeanMethods
is going to change how the application's bean interact with one another ? From my understand setting proxyBeanMethods
to false
is similiar to using @Lazy
annotation on the dependencies of a bean in which those dependencies will only be created once the methods that return them are called therefore improve the startup speed. Is there anything I'm missing ?
It isn't the same as @Lazy
and this is also explained in the javadoc of the property.
The default is true
meaning each @Bean
method will get proxied through CgLib. Each call to the method will pass through the proxy and assuming singleton scoped beans, it will return the same instance each time the method is called.
When setting it to false
no such proxy method will be created and each call to the method will create a new instance of the bean. It will act just as a factory method. This is basically the same as the so called Bean Lite Mode, or @Bean
methods on non-@Configuration
annotated classes.
Now the latter isn't the same as @Lazy
which will only defer the construction to the moment it is needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With