← Quiz: Spring Core and DI: all 10 questions
Quiz: Spring Core and DI · Question 10 of 10
When do you use a @Bean method instead of @Component?
When do you use a @Bean method instead of @Component?
- A.For every service class
- B.Only for controllers
- C.When the class comes from a library you cannot annotate, such as BCryptPasswordEncoder
- D.When the bean must be a prototype
Answer & explanation
Correct answer: When the class comes from a library you cannot annotate, such as BCryptPasswordEncoder
A @Bean method in a @Configuration class creates and returns the object for Spring.
Can you get the rest right without peeking?
Take the timed Quiz: Spring Core and DI quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →