D
D
DrFreez2013-07-15 14:37:33
Java
DrFreez, 2013-07-15 14:37:33

Spring. What is the service layer for?

In all guides, they give the following project structure:

image

In the same guides, looking at the code, you can only see that the service layer completely duplicates DAO. What is this layer for? How to use it correctly?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
J
javax, 2013-07-15
@javax

The service layer contains business logic, for the implementation of which it refers to different DAOs

I
IDVsbruck, 2013-07-16
@IDVsbruck

These are general words and terminology of a person who understands thoroughly or almost thoroughly the structure and principles of interaction inside the Spring container. Yes, and the logic is very often simple in services - to get data and sometimes transform it to return the control. It is clear that there are also complex services, but in the vast majority it is just getting data from the database according to criteria.
Using this framework for more than one year, I also often sinned by throwing out the service layer, delegating its functionality to the DAO layer (only as one guru from one resource correctly noted, in Spring's terminology, it is correct to call this layer not DAO, but the repository - Repository). It was simple and convenient, especially since for small projects, in fact, the code in the Tao and the service is repeated. And the differences are that @ Repository - our DAO - is a bean-singleton, and when it is accessed by several threads, which is a normal thing for MVC, access to the same data from different threads can occur. The visibility of @ Service is determined by the visibility of the calling @ Controller. Perhaps, with the definition and terminology, I have some tensions, and fine-tuning of the components can certainly be done, but the general principle and purpose have been transferred.

R
relgames, 2013-07-19
@relgames

But I've never understood the need for DAO. In fact, this is just a wrapper over the EntityManager. With the advent of Spring Data, this has become even more obvious. But I could be wrong, I don't have much experience in this area.

D
dikkini, 2013-11-28
@dikkini

policy layer instead of service. Service - DAO, Policy - business logic. In one project, I started doing this, and I got used to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question