This question may be of interest to you as well as this explanation.
You are mostly talking about the same things in each case, Spring just uses annotations so that when it scans them it knows what type of object you are creating or instantiating.
Basically everything request flows through the controller annotated with @Controller. Each method process the request and (if needed) calls a specific service class to process the business logic. These classes are annotated with @Service. The controller can instantiate these classes by autowiring them in @Autowire or resourcing them @Resource.
@Controller
@RequestMapping("/")
public class MyController {
@Resource private MyServiceLayer myServiceLayer;
@RequestMapping("/retrieveMain")
public String retrieveMain() {
String listOfSomething = myServiceLayer.getListOfSomethings();
return listOfSomething;
}
}
The service classes then perform their business logic and if needed, retrieve data from a repository class annotated with @Repository. The service layer instantiate these classes the same way, either by autowiring them in @Autowire or resourcing them @Resource.
@Service
public class MyServiceLayer implements MyServiceLayerService {
@Resource private MyDaoLayer myDaoLayer;
public String getListOfSomethings() {
List<String> listOfSomething = myDaoLayer.getListOfSomethings();
// Business Logic
return listOfSomething;
}
}
The repository classes make up the DAO, Spring uses the @Repository annotation on them. The entities are the individual class objects that are received by the @Repository layer.
@Repository
public class MyDaoLayer implements MyDaoLayerInterface {
@Resource private JdbcTemplate jdbcTemplate;
public List<String> getListOfSomethings() {
// retrieve list from database, process with row mapper, object mapper, etc.
return listOfSomething;
}
}
@Repository, @Service, and @Controller are specific instances of @Component. All of these layers could be annotated with @Component, it's just better to call it what it actually is.
So to answer your question, they mean the same thing, they are just annotated to let Spring know what type of object it is instantiating and/or how to include another class.