|
1 | | -[English Version](https://github.com/jkazama/ddd-java/tree/en) |
2 | | - |
3 | 1 | ddd-java |
4 | 2 | --- |
5 | 3 |
|
6 | | -## はじめに |
7 | | - |
8 | | -JSUG(日本Springユーザ会)の下記勉強会向けのサンプル実装です。 |
9 | | - |
10 | | -- 2014/11/27 「SpringBootを用いたドメイン駆動設計」 |
| 4 | +### Preface |
11 | 5 |
|
12 | | -> Spring Boot 3 の利用に伴い実装コードを Java17 へ切り替えています。 Java7 での実装コードを確認したいときは 1.x ブランチを参照してください。 |
| 6 | +It is DDD sample implementation from [Spring Boot](http://projects.spring.io/spring-boot/). |
| 7 | +It is not a framework, This is a simple example of the implementation based on Evans's DDD. |
13 | 8 |
|
14 | | -本サンプルでは[SpringBoot](http://projects.spring.io/spring-boot/)と[Lombok](http://projectlombok.org/)を利用してドメインモデリングの実装例を示します。実際に2007年くらいから現在に至るまで現場で利用されている実装アプローチなので、参考例の一つとしてみてもらえればと思います。 |
15 | | -※JavaDocに記載をしていますが、サンプルに特化させているので実際の製品コードが含まれているわけではありません。 |
16 | 9 |
|
17 | | -認証含む、より実践的な実装サンプルについては[sample-boot-hibernate](https://github.com/jkazama/sample-boot-hibernate)を参照してください。 |
18 | | -またUI側の実装サンプルについては[sample-ui-vue](https://github.com/jkazama/sample-ui-vue) / [sample-ui-react](https://github.com/jkazama/sample-ui-react)を参照してください。 |
| 10 | +#### Concept of Layering |
19 | 11 |
|
20 | | -### レイヤリングの考え方 |
| 12 | +It is three levels of famous models, but considers the infrastructure layer as cross-sectional interpretation. |
21 | 13 |
|
22 | | -オーソドックスな三層モデルですが、横断的な解釈としてインフラ層を考えます。 |
| 14 | +| Layer | | |
| 15 | +| -------------- | ----------------------------------------------------------- | |
| 16 | +| UI | Receive use case request | |
| 17 | +| Application | Use case processing (including the outside resource access) | |
| 18 | +| Domain | Pure domain logic (not depend on the outside resource) | |
| 19 | +| Infrastructure | DI container and ORM, various libraries | |
23 | 20 |
|
24 | | -- UI層 - ユースケース処理を公開(必要に応じてリモーティングや外部サイトを連携) |
25 | | -- アプリケーション層 - ユースケース処理を集約(外部リソースアクセスも含む) |
26 | | -- ドメイン層 - 純粋なドメイン処理(外部リソースに依存しない) |
27 | | -- インフラ層 - DIコンテナやORM、各種ライブラリ、メッセージリソースの提供 |
| 21 | +Usually perform public handling of UI layer using Thymeleaf, but this sample assume use of different types of clients and perform only API offer in RESTfulAPI. |
28 | 22 |
|
29 | | -UI層の公開処理は通常Thymeleafを用いて行いますが、本サンプルでは異なる種類のクライアント利用を想定してRESTfulAPIでの公開を前提とします。(API利用前提のサーバ解釈) |
| 23 | +#### Use policy of Spring Boot |
30 | 24 |
|
31 | | -### SpringBootの利用方針 |
| 25 | +Spring Boot is available for various usage, but uses it in the following policy with this sample. |
32 | 26 |
|
33 | | -SpringBootは様々な利用方法が可能ですが、本サンプルでは以下のポリシーを用います。 |
| 27 | +- Use standard definitions as much as possible, such as DB settings. |
| 28 | +- The configuration file uses yml. do not use xml files for Bean definition. |
| 29 | +- The exception handling defines it in a endpoint (RestErrorAdvice). |
34 | 30 |
|
35 | | -- DBの設定等、なるべく標準定義をそのまま利用する。 |
36 | | -- 設定ファイルはymlを用いる。Bean定義にxml等の拡張ファイルは用いない。 |
37 | | -- ライブラリ化しないので@Beanによる将来拡張性を考慮せずにクラス単位でBeanベタ登録。 |
38 | | -- 例外処理は終端(RestErrorAdvice/RestErrorCotroller)で定義。 |
39 | | -- サンプル用途 |
| 31 | +#### Use policy of Java coding |
40 | 32 |
|
41 | | -### Javaコーディング方針 |
| 33 | +- Java17 over |
| 34 | +- Use Lombok positively and remove diffuseness. |
| 35 | +- The name as possible briefly. |
| 36 | +- Do not abuse the interface. |
| 37 | +- DTO becoming a part of the domain defines it in an internal class. |
42 | 38 |
|
43 | | -Java17以上を前提としていますが、従来のJavaで推奨される記法と異なっている観点も多いです。 |
44 | | -以下は保守性を意識した上で簡潔さを重視した方針となっています。 |
| 39 | +#### Resource |
45 | 40 |
|
46 | | -- Lombokを積極的に利用して冗長さを排除 |
47 | | -- 名称も既存クラスと重複しても良いのでなるべく簡潔に |
48 | | -- インターフェースの濫用をしない |
49 | | -- ドメインの一部となるDTOなどは内部クラスで表現 |
50 | | - |
51 | | -### パッケージ構成 |
52 | | - |
53 | | -パッケージ/リソース構成については以下を参照してください。 |
| 41 | +Refer to the following for the package / resource constitution. |
54 | 42 |
|
55 | 43 | ``` |
56 | 44 | main |
57 | 45 | java |
58 | 46 | sample |
59 | | - context … インフラ層 |
60 | | - controller … UI層 |
61 | | - model … ドメイン層 |
62 | | - usecase … アプリケーション層 |
63 | | - util … 汎用ユーティリティ |
64 | | - - Application.java … 実行可能な起動クラス |
| 47 | + context … Infrastructure Layer |
| 48 | + controller … UI Layer |
| 49 | + model … Domain Layer |
| 50 | + usecase … Application Layer |
| 51 | + util … Utilities |
| 52 | + - Application.java … Bootstrap |
65 | 53 | resources |
66 | | - - application.yml … 設定ファイル |
67 | | - - messages-validation.properties … 例外メッセージリソース |
68 | | - - messages.properties … メッセージリソース |
| 54 | + - application.yml … Spring Boot Configuration |
| 55 | + - messages-validation.properties … Validation Message Resources |
| 56 | + - messages.properties … Label Message Resources |
69 | 57 | ``` |
70 | 58 |
|
71 | | -## サンプルユースケース |
72 | | - |
73 | | -サンプルユースケースとしては以下を想定します。 |
74 | | - |
75 | | -- **口座残高100万円を持つ顧客**が出金依頼(発生 T, 受渡 T + 3)をする。 |
76 | | -- **システム**が営業日を進める。 |
77 | | -- **システム**が出金依頼を確定する。(確定させるまでは依頼取消行為を許容) |
78 | | -- **システム**が受渡日を迎えた入出金キャッシュフローを口座残高へ反映する。 |
79 | | - |
80 | | -## 動作確認 |
81 | | - |
82 | | -サンプルはGradleを利用しているので、IDEやコンソールで動作確認を行うことができます。 |
83 | | - |
84 | | -### VSCode |
85 | | - |
86 | | -開発IDEである[VSCode](https://code.visualstudio.com)で本サンプルを利用するには、事前に以下の手順を行っておく必要があります。 |
| 59 | +## Use Case |
87 | 60 |
|
88 | | -- Java17以上のインストール |
89 | | - - DevContainer 利用時は不要 |
90 | | -- Java / Lombok / Gradle の Extension 追加 |
| 61 | +Consider the following as a sample use case. |
91 | 62 |
|
92 | | -次の手順で本サンプルをプロジェクト化してください。 |
| 63 | +- A customer with an account balance requests withdrawal. (Event T, Delivery T + 3) |
| 64 | +- The system closes the withdrawal request. (Allows cancellation of request until closing) |
| 65 | +- The system sets the business day to the forward day. |
| 66 | +- The system reflects the cash flow on delivery date to the account balance. |
93 | 67 |
|
94 | | -1. ダウンロードした*java-ddd*ディレクトリ直下へコンソールで移動 |
95 | | -1. 「code .」で起動 |
| 68 | +### Getting Started |
96 | 69 |
|
97 | | -次の手順で本サンプルを実行してください。 |
| 70 | +This sample uses [Gradle](https://gradle.org/), you can check the operation without trouble with IDE and a console. |
98 | 71 |
|
99 | | -1. 左サイドメニューの「Run And Debug」で *Run ddd-java* を選択肢て実行 |
100 | | -1. *DEBUG CONSOLE*タブに「Started Application」という文字列が出力されればポート8080で起動が完了 |
| 72 | +#### Server Start (VSCode DevContainer) |
101 | 73 |
|
102 | | -> Linux や WSL 上で DevContainer を立ち上げて確認することも可能です。 Open Container のダイアログが出たらOKを押下してください。 |
103 | | -> DevContainer の起動に失敗する時はポート重複が無いか、vscode-remote-release の [#7303](https://github.com/microsoft/vscode-remote-release/issues/7303) の問題を踏んでいないか確認してください。 #7303 の問題だった時は Extension の DevContainers を `v0.251.0` へ下げることでうまくいくことがあります。 |
| 74 | +It is necessary to do the following step. |
104 | 75 |
|
105 | | -### STS(Eclipse) |
| 76 | +- Check Instablled Docker. |
| 77 | +- Check Instablled VSCode with DevContainer Extension. |
106 | 78 |
|
107 | | -開発IDEである[STS](https://spring.io/tools/sts)で本サンプルを利用するには、事前に以下の手順を行っておく必要があります。 |
108 | | -※EclipseにSpringIDEプラグインを入れても可 |
| 79 | +Do the preparations for this sample in the next step. |
109 | 80 |
|
110 | | -- Java17以上のインストール |
111 | | -- [Lombok](http://projectlombok.org/download.html)のパッチ当て(.jarを実行してインストーラの指示通りに実行) |
| 81 | +1. You move to the cloned *ddd-java* directory. |
| 82 | +1. Run command `code .`. |
| 83 | +1. Choose *Open Container* |
112 | 84 |
|
113 | | -次の手順で本サンプルをプロジェクト化してください。 |
114 | | -※コンパイルエラーになる時は、Javaコンパイラの設定が17以上になっているかを確認してください。 |
| 85 | +Do the server start in the next step. |
115 | 86 |
|
116 | | -1. パッケージエクスプローラから「右クリック -> Import」で*Exsisting Project into Workspace*を選択して*Next*を押下 |
117 | | -1. *Root folder:*にダウンロードした*ddd-java*ディレクトリを指定して*Build Model*を押下 |
118 | | -1. *Project*で*ddd-java*を選択後、*Finish*を押下(依存ライブラリダウンロードがここで行われます) |
| 87 | +1. Open VSCode "Run And Debug". |
| 88 | +1. Choose `Run ddd-java`. |
| 89 | +1. If console show "Started Application", start is completed in port 8080. |
| 90 | +1. Run command `curl http://localhost:8080/actuator/health` |
119 | 91 |
|
120 | | -次の手順で本サンプルを実行してください。 |
| 92 | +#### Server Start (Console) |
121 | 93 |
|
122 | | -1. *Application.java*に対し「右クリック -> Run As -> Java Application」 |
123 | | -1. *Console*タブに「Started Application」という文字列が出力されればポート8080で起動が完了 |
| 94 | +Run application from a console of Windows / Mac in Gradle. |
124 | 95 |
|
125 | | -### コンソール |
| 96 | +It is necessary to do the following step. |
126 | 97 |
|
127 | | -Windows/Macのコンソールから実行するにはGradleのコンソールコマンドで行います。 |
128 | | -※事前にJava17以上のインストールが必要です。 |
| 98 | +- Check Instablled JDK17+. |
129 | 99 |
|
130 | | -1. ダウンロードした*java-ddd*ディレクトリ直下へコンソールで移動 |
131 | | -1. 「gradlew bootRun」を実行 |
132 | | -1. コンソールに「Started Application」という文字列が出力されればポート8080で起動が完了 |
| 100 | +Do the server start in the next step. |
133 | 101 |
|
| 102 | +1. You move to the cloned *ddd-java* directory. |
| 103 | +1. Run command `gradlew bootRun`. |
| 104 | +1. If console show "Started Application", start is completed in port 8080 |
| 105 | +1. Run command `curl http://localhost:8080/actuator/health` |
134 | 106 |
|
135 | | -### ブラウザ |
| 107 | +### Check Use Case |
136 | 108 |
|
137 | | -STSまたはコンソールで8080ポートでサーバを立ち上げた後、ブラウザから下記URLへアクセスする事でRESTfulAPIの実行テストを実施可能です。 |
138 | | -※本来なら情報更新系処理はPOSTで取り扱うべきですが、UIの無いデモ用にGETでのアクセスを許容しています。 |
139 | | -※パラメタは?key=valueで繋げて渡してください。 |
| 109 | +After launching the server on port 8080, you can test execution of RESTful API by accessing the following URL from console. |
140 | 110 |
|
141 | | -顧客向けユースケース |
| 111 | +#### Customer Use Case |
142 | 112 |
|
143 | | -- http://localhost:8080/asset/cio/withdraw |
144 | | - - 振込出金依頼 [accountId: sample, currency: JPY, absAmount: 出金依頼金額] |
145 | | -- http://localhost:8080/asset/cio/unprocessedOut |
146 | | - - 振込出金依頼未処理検索 |
| 113 | +- `curl -X POST -H "Content-Type: application/json" -d '{"accountId" : "sample" , "currency" : "JPY", "absAmount": 1000}' http://localhost:8080/asset/cio/withdraw` |
| 114 | + - Request for withdrawal. |
| 115 | +- `curl 'http://localhost:8080/asset/cio/unprocessedOut'` |
| 116 | + - Search for outstanding withdrawal requests |
147 | 117 |
|
148 | | -社内向けユースケース |
| 118 | +#### Internal Use Case |
149 | 119 |
|
150 | | -- http://localhost:8080/admin/asset/cio |
151 | | - - 振込入出金依頼検索 [updFromDay: 更新From(yyyyMMdd), updToDay: 更新To(yyyyMMdd)] |
| 120 | +- `curl 'http://localhost:8080/admin/asset/cio?updFromDay=yyyy-MM-dd&updToDay=yyyy-MM-dd'` |
| 121 | + - Search for deposit and withdrawal requests. |
| 122 | + - Please set real date for upd\*Day |
152 | 123 |
|
153 | | -バッチ向けユースケース |
| 124 | +#### Batch Use Case |
154 | 125 |
|
155 | | -- http://localhost:8080/system/job/daily/processDay |
156 | | - - 営業日を進める(単純日回しのみ) |
157 | | -- http://localhost:8080/system/job/daily/closingCashOut |
158 | | - - 当営業日の出金依頼を締める |
159 | | -- http://localhost:8080/system/job/daily/realizeCashflow |
160 | | - - 入出金キャッシュフローを実現する(受渡日に残高へ反映) |
| 126 | +- `curl -X POST http://localhost:8080/system/job/daily/closingCashOut` |
| 127 | + - Close the withdrawal request. |
| 128 | +- `curl -X POST http://localhost:8080/system/job/daily/processDay` |
| 129 | + - Set the business day to the next day. |
| 130 | +- `curl -X POST http://localhost:8080/system/job/daily/realizeCashflow` |
| 131 | + - Realize cash flow. (Reflected to the balance on the delivery date) |
161 | 132 |
|
| 133 | +> Please execute according to the business day appropriately |
162 | 134 |
|
163 | | -## License |
| 135 | +### License |
164 | 136 |
|
165 | | -本サンプルのライセンスはコード含めて全て*MIT License*です。 |
166 | | -Spring Bootを用いたプロジェクト立ち上げ時のベース実装サンプルとして気軽にご利用ください。 |
| 137 | +The license of this sample includes a code and is all *MIT License*. |
| 138 | +Use it as a base implementation at the time of the project start using Spring Boot. |
0 commit comments