Avatar ·

Difference between @Component, @Repository and @Service in Spring Framework

Hello everyone! I'm a beginner Java developer learning Spring Framework. I'm writing my first application — a simple online store. I have several classes: ProductService, ProductRepository and ProductController. I know that all of them should be Spring beans, but I don't understand which annotation to use for which class. Everywhere they write that you can just put @Component on everything, but I've seen that experienced developers use @Repository for the DAO layer and @Service for services. What's the difference? I tried to write like this: ```java @Component public class ProductRepository { public List findAll() { // working with DB here } } @Service public class ProductService { @Autowired private ProductRepository repository; } @Controller public class ProductContr