Search code examples
javaspringhibernatespring-mvcpojo

Spring MVC: correct package for POJO used in services


I am developing an MVC application on Spring Boot, here is the structure of its packages:

enter image description here enter image description here enter image description here

Package 'domain' contains JPA entities and POJOs for Redis; package "repository" contains Spring Data repositories to work with domain model; package "services" contains service-layer and works with repositories; package "controller" contains REST controllers working with services.

But usually, services need to use some POJOs for service-specific data and pass it to controller. For example, the class FeedPage, which essentially POJO, aggregates the data, calculated FeedService and is not related to the database.

Could you please assist a right package for such POJOs: 1) Store it in "domain" along with DB entites 2) Store it in services package ( services.feed)? 3) Create package "model" under each service and store POJOs there

Thanks!


Solution

  • Stumbled upon my old question.

    Ended up adding a DOs classes into corresponding packages in the service layer where it's necessary. A naming convention for the DOs is xxxDO which let me easily notice such classes in a project tree.