Which annotation is used to define a bean in the Spring context?

  • @Bean
  • @Component
  • @Inject
  • @Service
The @Bean annotation is used to define a bean in the Spring context. When you annotate a method with @Bean, it tells Spring that the method should be used to create and configure a bean. This is commonly used for defining custom beans in Java-based Spring configurations. The other annotations (@Inject, @Component, and @Service) have different purposes and are not used for defining beans in the same way as @Bean.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *