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.
Loading...
Related Quiz
- What is the significance of Garbage Collection optimization in Spring Boot, and how can it impact application performance?
- In unit testing of Spring Boot applications, the _____ method of Assert class is commonly used to check if the specified condition is true.
- What is the primary purpose of monitoring in a Spring Boot application?
- In a Spring Cloud microservices architecture, _____ is primarily used for allowing services to discover each other.
- For optimizing database connection pooling in Spring Boot, adjusting the _____ property is crucial.