A sample project following Domain Driven Design with Spring Data JPA
A sample project following Domain Driven Design with Spring Data JPA
(C) Christoph Knabe, 2017-03-17 ... 2018-10-11
In this project I am trying to apply principles of Domain Driven Design. In contrary to full-blown DDD examples on the web I am applying here some simplifications. This sample application is used for a course on Software Engineering at Beuth University of Applied Sciences Berlin.
This project uses
springfox-swaggerfor generating documentation and user interface for the REST service
Detailed version indications you can find in the file
pom.xml.
By
mvn clean testall necessary libraries will be fetched, the project will be compiled, exception message texts will be collected and the test suite will be executed.
After this is working you can import the Maven project into your Java IDE (Spring Tool Suite is recommended, as AspectJ weaving is needed for the compile phase).
You can run the application (a REST server) in your IDE by running class
de.beuth.knabe.spring_ddd_bank.Applicationor on the command line after
mvn packageby
java -jar target/spring-ddd-bank-0.1-SNAPSHOT.jar. In the last lines of the log you will see the number of the port (usually 8080), on which the server will listen. You can stop it by typing <Ctrl/c>.
Modelling the domain layer as one package, which does not depend on any other package besides standard Java SE packages as
java.timeand
javax.persistence. The latter only for the JPA annotations.
Avoid an anemic domain model by having relevant business logic methods in entity class
Client.
The Domain Layer references required services only by self-defined, minimal interfaces (in package
domain.imports).
Implementing required services in the infrastructure layer (in package
infrastructure).
Linking together required services and their implementations by Dependency Injection.
Implementing an interface layer for external access to the application. This is implemented as a REST service in package
rest_interface.
.uxf.
In the file
MessageText.properties. The editable original with some fixed message texts is in
src/main/resources/. By Maven phase
compilethis file is copied to
target/classes/. During the following phase
process-classesthe exception message texts are extracted from the JavaDoc comments of all exceptions under
src/main/java/by the
ExceptionMessagesDocletas configured for the
maven-javadoc-plugin. They are appended to the message text file in
target/classes/. This process is excluded from m2e lifecycle mapping in the
pom.xml.
Amounta better value object by freezing its attributes. Seems, that for this goal Hibernate has to be used instead of JPA.
AccountAccess, because this class models an m:n association between
Clientand
Account. There should not be a possibility for several links between a client and an account. This would require the usage of
client.idand
account.idas a composite ID for
AccountAccess. Not so easy, see JPA: How to associate entities with relationship attributes?