Spring supports multiple types annotations such as @Component, @service, @Repository. All theses can be found under the org.springframework.stereotype package and @Bean can be found under org.springframework.context.annotation package.
When classes in our application are annotated with any of the above mentioned annotation then during project startup spring scan(using @ComponentScan) each class and inject the instance of the classes to the IOC container. Another thing the @ComponentScan would do is running the methods with @Bean on it and restore the return object to the Ioc Container as a bean.
Before we deep dive into ( @Component vs @service vs @Repository ) first it's better to understand the differences between @Bean and @Component

@Component vs @Repository vs @Service
In most typical applications, we have distinct layers like data access, presentation, service, business, etc. Additionally, in each layer we have various beans. To detect these beans automatically, Spring uses classpath scanning annotations.Then it registers each bean in the ApplicationContext.
Here's a short overview of a few of these annotations:
- @Component is a generic stereotype for any Spring-managed component.
- @Service annotates classes at the service layer.
- @Repository annotates classes at the persistence layer, which will act as a database repository.
@Component Annotation
@Component is a class level annotation.We can use @Component across the application to mark the beans as Spring's managed components. Spring will only pick up and register beans with @Component, and doesn't look for @Service and @Repository in general.
They are registered in ApplicationContext because they are annotated with @Component
As stated, @Component is the parent of all stereotype annotations. When Spring performs a component scan, it only looks for classes marked with @Component annotations.
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
public @interface Component {
String value() default "";
}
We can use this annotation on all the classes and it won’t cause any difference.
@Service Annotation
We mark beans with @Service to indicate that they're holding the business logic. Besides being used in the service layer, there isn't any other special use for this annotation.
The @Service is child of component and used to denote classes from the service layer of the application.
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Service {
@AliasFor(
annotation = Component.class
)
String value() default "";
}
@Repository Annotation
@Repository’s job is to catch persistence-specific exceptions and re-throw them as one of Spring’s unified unchecked exceptions.
For this, Spring provides PersistenceExceptionTranslationPostProcessor, which we are required to add in our application context (already included if we're using Spring Boot):
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
This bean post processor adds an advisor to any bean that’s annotated with @Repository.
Similarly, @Repository is also a child of component annotation and used on the classes that belong to persistence data access layer and serves as a data repository.
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Repository {
@AliasFor(
annotation = Component.class
)
String value() default "";
}
Summary
@Service and @Repository are special cases of @Component. They are technically the same, but we use them for the different purposes.It's always a good idea to choose the annotation based on their layer conventions.