Logo InterviewVault

Welcome back, Sujit Kumar Mishra

SKM

Revision Mode

Document technical questions and best-practice answers.

Cancel

Can you explain the difference between @Component, @Service and @Repository annotations in SpringBoot? 

@Component, @Service, and @Repository are all used in Spring Boot to let Spring manage classes for us.


1: @Component:

For any general class you want Spring to manage.

2: @Service:

For classes that handle business logic (like calculations or processing).

3: @Repository:

For classes that deal with database operations (like saving or fetching data).


Summary:

1: @Component = any class

2: @Service = business logic

3: @Repository = database access

Ready for commit