What is the Use of @Bean Annotation in Spring?

The @Bean annotation in Spring is used to declare a method that returns a Spring bean, which is managed by the Spring IoC (Inversion of Control) container. It is typically used in configuration classes annotated with @Configuration.


How @Bean Internally Works

  1. Spring Configuration Class:
  2. Bean Creation and Management:
  3. Proxy Mechanism:

Possible Ways to Use @Bean

1. name


2. initMethod