3

Spring doc mentions "lite" mode @Bean where the annotation is declared not within a @Configuration class.

The primary difference seems to be whether the @Bean method is proxied by cglib.

But practically, when is it a good fit to use lite mode @Bean methods (over a plain java method)?

wlnirvana
  • 1,811
  • 20
  • 36
  • 2
    The short answer never, as it only leads to unexpected behavior. A lite bean method is basically just a simple factory method, each time it is called it will create a new instance (that is the lite part, and the part that leads to confusion). – M. Deinum May 26 '21 at 06:11
  • It can be used when there is requirement to have two beans (instances) of same type, where each instance behaves differently (different constructor args etc.). – user3734782 May 26 '21 at 08:41
  • We can define a bean using @Bean annotation on a method. But I can't think of any real use case that you will need to call that particular bean method directly. – Abe Dec 13 '22 at 22:47

0 Answers0