🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.For every service class
  2. B.Only for controllers
  3. C.When the class comes from a library you cannot annotate, such as BCryptPasswordEncoder
  4. 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 →