This question may interest you, and this is an explanation .
Basically you are talking about the same things, Spring just uses annotations, so when it scans them, it knows what type of object you are creating or creating.
Basically, all requests are sent through a controller annotated using @Controller . Each method processes the request and (if necessary) calls a specific class of service for processing business logic. These classes are annotated using @Service . The controller can create these classes by auto-updating them in @Autowire or storing them with @Resource.
@Controller @RequestMapping("/") public class MyController { @Resource private MyServiceLayer myServiceLayer; @RequestMapping("/retrieveMain") public String retrieveMain() { String listOfSomething = myServiceLayer.getListOfSomethings(); return listOfSomething; } }
Service classes then execute their business logic and, if necessary, retrieve data from the repository class annotated with @Repository . The service layer creates these classes the same way, either by auto-arranging them in @Autowire or their resource @ Resource .
@Service public class MyServiceLayer implements MyServiceLayerService { @Resource private MyDaoLayer myDaoLayer; public String getListOfSomethings() { List<String> listOfSomething = myDaoLayer.getListOfSomethings();
Repository classes make up the DAO, Spring uses the @Repository annotation. Objects are individual class objects obtained by the @Repository level.
@Repository public class MyDaoLayer implements MyDaoLayerInterface { @Resource private JdbcTemplate jdbcTemplate; public List<String> getListOfSomethings() {
@Repository, @Service and @Controller are concrete instances of @Component . All of these layers can be annotated using @Component, itβs just better to call it what it really is.
So, to answer your question, they mean the same thing, they are simply annotated so that Spring knows what type of object it creates and / or how to include another class.