Spring Boot + Java [ DDD Sample ]
This is a DDD sample implementation using Spring Boot.
It is not a framework, but a simple example of implementation based on Evans’s DDD.
This approach is straightforward and based on Evans’s book, rather than verbose approaches like Clean Architecture or Hexagonal Architecture.
This follows the famous three-layer model, but considers the infrastructure layer as a cross-cutting concern.
Layer | |
---|---|
UI | Receives use case requests |
Application | Use case processing (including external resource access) |
Domain | Pure domain logic (does not depend on external resources) |
Infrastructure | DI container, ORM, and various libraries |
Usually, the UI layer handles public interactions using Thymeleaf, but this sample assumes the use of different types of clients and only provides APIs through RESTful endpoints.
Spring Boot can be used in various ways, but this sample follows the following policies:
Refer to the following for the package and resource structure:
main
java
sample
context … Infrastructure Layer
controller … UI Layer
model … Domain Layer
usecase … Application Layer
util … Utilities
- Application.java … Bootstrap
resources
- application.yml … Spring Boot Configuration
- messages-validation.properties … Validation Message Resources
- messages.properties … Label Message Resources
Consider the following as a sample use case:
This sample uses Gradle. You can check the operation easily with an IDE or console.
The following steps are required:
Prepare this sample with the following steps:
code .
.Start the server with the following steps:
Run ddd-java
.curl http://localhost:8080/actuator/health
.Run the application from a Windows/Mac console using Gradle.
The following steps are required:
Start the server with the following steps:
./gradlew bootRun --args='--spring.profiles.active=dev'
.curl http://localhost:8080/actuator/health
.After launching the server on port 8080, you can test the RESTful API execution by accessing the following URLs from the console:
curl -X POST -H "Content-Type: application/json" -d '{"accountId" : "sample" , "currency" : "JPY", "absAmount": 1000}' http://localhost:8080/asset/cio/withdraw
curl 'http://localhost:8080/asset/cio/unprocessedOut'
curl 'http://localhost:8080/admin/asset/cio?updFromDay=yyyy-MM-dd&updToDay=yyyy-MM-dd'
curl -X POST http://localhost:8080/system/job/daily/closingCashOut
curl -X POST http://localhost:8080/system/job/daily/processDay
curl -X POST http://localhost:8080/system/job/daily/realizeCashflow
Please execute these according to the business day appropriately.
The license for this sample code is MIT License.
Use it as a base implementation when starting a project using Spring Boot.