Junior — Middle
Can the @Component annotation be applied to an interface in Spring Framework?
sobes.tech AI
Answer from AI
The @Component annotation in the Spring Framework is used to mark classes as components that will be automatically detected and registered in the Spring context (IoC container). You cannot apply @Component to an interface because an interface cannot be instantiated, and Spring will not be able to create a bean based on it.
Typically, @Component is placed on classes that implement interfaces or are themselves components. If you need to register a bean by interface, it is done through the implementation class, not the interface.