The @Bean
annotation is used to indicate that a method instantiates, configures, and initializes a new object to be managed by the Spring IoC container. @Bean is most often used with @Configuration
beans. Annotating a class with @Configuration
indicates that its primary purpose is as a source of bean definitions.
While a name()
attribute is available, the default strategy for determining the name of a bean is to use the name of the @Bean
method.
@Bean was created to avoid coupling Spring and your business rules in compile time. It means you can reuse your business rules in other frameworks like PlayFramework or JEE.
@Configuration
is meta-annotated with @Component
, therefore @Configuration
classes are candidates for component scanning and therefore may also take advantage of @Autowired
/@Inject
like any regular @Component
.