Recall & Review
beginner
What is the purpose of the
@Component annotation in Spring Boot?The <code>@Component</code> annotation tells Spring to create and manage an instance of the class as a bean. It makes the class available for dependency injection.Click to reveal answer
beginner
How does Spring Boot find classes annotated with
@Component?Spring Boot scans the packages specified in the application for classes with
@Component and automatically registers them as beans in the application context.Click to reveal answer
beginner
Can
@Component be used on interfaces or only on classes?<code>@Component</code> should be used on classes, not interfaces, because Spring creates an instance of the class to manage as a bean.Click to reveal answer
intermediate
What is the difference between
@Component and @Service annotations?@Service is a specialized form of @Component used to mark service layer classes. Functionally they are similar, but @Service adds semantic meaning.Click to reveal answer
intermediate
How can you give a custom name to a bean created with
@Component?You can specify a name by passing a string value to
@Component("customName"). This name can be used to refer to the bean in the Spring context.Click to reveal answer
What does the
@Component annotation do in Spring Boot?✗ Incorrect
@Component marks a class so Spring creates and manages it as a bean.Where should you place the
@Component annotation?✗ Incorrect
@Component is used on classes to tell Spring to create beans from them.Which annotation is a specialized form of
@Component for service classes?✗ Incorrect
@Service is a specialized @Component for service layer classes.How does Spring Boot find classes annotated with
@Component?✗ Incorrect
Spring Boot scans packages to find
@Component classes and registers them automatically.How can you assign a custom name to a bean created with
@Component?✗ Incorrect
You can pass a string to
@Component to name the bean.Explain what the
@Component annotation does in Spring Boot and why it is useful.Think about how Spring knows which classes to create and manage.
You got /4 concepts.
Describe how you can customize the name of a bean created with
@Component and why you might want to do that.Consider how Spring identifies beans in the application context.
You got /3 concepts.