Quizzes@ComponentScan & Stereotypes — Concept Check
intermediate
spring-boot

@ComponentScan & Stereotypes — Concept Check

Questions on @ComponentScan & Stereotypes. @ComponentScan instructs Spring to detect @Component, @Service, @Repository, and @Controller classes and register them as beans automatically.

5 minutes 5 questions Pass at 70%
Time Limit
5 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

5 questions on @ComponentScan & Stereotypes — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A Spring Boot application is not picking up a certain @Service annotated class. What could be a potential reason?

    • AThe class is not in a package scanned by @ComponentScan.
    • BThe class is not in the same package as the main application class.
    • CThe class is missing a @Repository annotation.
    • DThe class is not marked with @Controller.
  2. 2.A developer uses @Service("legacyOrderService") for a bean. What is the purpose of specifying "legacyOrderService"?

    • ATo ensure it is the primary bean for injection.
    • BTo specify the package where the service is located.
    • CTo override the default bean name with a custom name.
    • DTo indicate that the service is deprecated.
  3. 3.If two beans have the same name in a Spring application, what happens by default?

    • AThe last definition wins in @ComponentScan.
    • BSpring uses the first bean defined.
    • CSpring throws a conflict exception in all cases.
    • DSpring ignores both beans.
  4. 4.What is the role of the @Repository annotation in Spring?

    • ATo mark a class for transaction management.
    • BTo indicate a class is part of the service layer.
    • CTo specify a class is a REST controller.
    • DTo translate JDBC/JPA exceptions to DataAccessException.
  5. 5.A developer uses @Primary on one of two @Service beans. What is the effect of this annotation?

    • AIt makes the annotated bean the default for injection when multiple beans of the same type exist.
    • BIt excludes the annotated bean from being scanned.
    • CIt marks the bean as deprecated.
    • DIt ensures the bean is always injected by name.