0

My next application is a maven multi-module application with this structure:

main-app

model sub-project
service sub-project
front-end sub-project

In the model sub-project there are all entities for application domain, in service sub-project the are the Spring Boot Controller and RestController and front-end sub-project is a simple web application with thymeleaf template engine.

Now i've a question about JPARepository (from spring boot implementation) interfaces for entities! Where should this object be? In service or model sub-project?

orion91
  • 47
  • 3
  • 8

1 Answers1

0

I would create four modules:

  • ui
  • web: controllers
  • domain: entities, value objects, services interfaces and implementations and repositories interfaces
  • persistence: repositories implementations

Take a look at https://en.wikipedia.org/wiki/Dependency_inversion_principle and Implementing Dependency Inversion Principle using Maven and Spring in order to understand why interfaces are in the domain module.

Diego Marin Santos
  • 1,923
  • 2
  • 15
  • 29
  • Thanks for your help! In my specific case don't needed implementations for repositories. I've simple interface that extends JPARepository or CrudRepository from Spring Data JPA A.P.I... Can i've this with entities in model sub-project or needed persistence sub-project anyway? Domain sub-project is simple jar for my implementation, i don't have spring boot jpa configuration properties in this sub-project, it should be in your web module? – orion91 Oct 22 '18 at 17:38
  • That's a good question. The point of creating a persistence module is to move implementation classes and technology specific dependencies to a new module different from where the repository interface was defined. In the case of Spring Data when there is no custom implementation classes, it doesn't make sense to create a new module only to define dependencies. I don't even know if it would be possible as you have to extend a Spring interface when you define your repository interface and your domain module shouldn't be aware of the existence of your persistence module. – Diego Marin Santos Oct 23 '18 at 16:51
  • Thanks so much Diego for your interesting about my question! Currently i try to have all my model class in first sub-project, without spring jpa repository interfaces here, in service sub-project i'll setup spring jpa configuration with all jpa repository for retrive database data. – orion91 Oct 23 '18 at 19:39