In a canonical Spring MVC implementation, the architecture goes something like this
+--controller
| |
| +--MyController (@Controller, calling MyService)
|
+--service
| |
| +--MyService (interface)
| +--MyServiceImpl (@Service, calls MyDAO)
|
+--dao
| |
| +--MyDAO (interface)
| +--MyDAOImpl (@Repository, MyEntity CRUD)
|
+--entity
|
+--MyEntity (@Entity, corresponding to my_table in DB)
My question is simple: What does the use of the @Service
contribute to the call hierarchy? Most service classes I've seen simply encapsulate methods from the DAO.
E.g.:
@Transactional
public List<Entity> getEntities() {
return entityDAO.getEntities();
}
@Transactional
public void saveEntity(Entity val) {
entityDAO.saveEntity(val);
}
Why not just bypass it and call the DAO
directly from the @Controller
?
RELATED: Is it bad practice that a controller calls a repository instead of a service? (formulated more abstractly outside any framework)