Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProxyBeanMethods in Spring

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 ?

like image 833
kungho Avatar asked Dec 11 '22 00:12

kungho


1 Answers

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.

like image 193
M. Deinum Avatar answered Dec 22 '22 00:12

M. Deinum