web プロジェクトの設定
web プロジェクトで必要な設定を解説します。
依存ライブラリの設定
web プロジェクトで利用を推奨するライブラリは以下の通りです。
-
spring-boot-starter-webmvc:Spring MVC を使用して Web アプリケーションを構築するためのスターター
-
h2:テストやローカル実行で利用する組み込みの H2 データベース
-
spring-boot-h2console:H2 Database の Web コンソールを有効化するためのライブラリ
-
spring-boot-starter-actuator: ヘルスチェックを含めたアプリケーション監視・管理機能を構築するためのスターター
-
spring-boot-starter-log4j2: Spring Boot アプリケーションで Apache Log4j 2 (以降 log4j2 )を使用するためのスターター
-
spring-boot-starter-thymeleaf:Thymeleaf テンプレートエンジンを使用して Web アプリケーションを構築するためのスターター
-
spring-boot-starter-test:Spring Boot アプリケーションをテストするためのスターター
-
spring-boot-starter-webmvc-test:Spring MVC アプリケーションをテストするためのライブラリ
上記のライブラリを依存ライブラリとして、 以下のように build.gradle の dependencies ブロックに追加します。
| web/build.gradle |
|---|
| dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
implementation 'com.h2database:h2:x.x.x'
implementation 'org.springframework.boot:spring-boot-h2console'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
}
|
各依存ライブラリのバージョンの参照先
依存プロジェクトの設定
web プロジェクトは a-function 、 b-function 、 system-common を参照しています。 そのため、 build.gradle で以下のように他のプロジェクトを依存関係に含めます。
| web/build.gradle |
|---|
| dependencies {
implementation project(':a-function')
implementation project(':b-function')
implementation project(':system-common')
}
|
Spring Boot の設定
Spring Boot の設定は CSR 編と同様です。
こちら を参照して、 Spring Boot の設定を追記してください。
ロギングライブラリの除外設定
ロギングライブラリの除外設定は CSR 編と同様です。
こちら を参照して、ロギングライブラリの除外設定を追記してください。
ログの設定
ログの設定は CSR 編と同様です。
こちら を参照して、ログの設定を追記してください。
ここまでを実行した後に、適切にビルドが実行できるかを確認します。 ターミナルを用いてルートプロジェクト直下で以下を実行してください。
ここまでの手順を実行した際の web/build.gradle の例
| web/build.gradle |
|---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 | plugins {
id 'java'
id 'org.springframework.boot' version 'x.x.x'
id 'io.spring.dependency-management' version 'x.x.x'
}
group = 'プロジェクトのグループ名'
version = 'x.x.x-SNAPSHOT'
description = 'プロジェクトの説明'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(x)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
implementation 'com.h2database:h2:x.x.x'
implementation 'org.springframework.boot:spring-boot-h2console'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation project(':a-function')
implementation project(':b-function')
implementation project(':system-common')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
// その他、プロジェクトに必要な依存ライブラリは任意で追加してください。
}
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
}
tasks.named('test') {
useJUnitPlatform()
}
|
メッセージ読込に関する設定
他サブプロジェクトで管理されているメッセージを読み込む場合は、こちら を参照して、設定を追記してください。
H2 Database をサーバーモードで起動する設定
H2 Database をサーバーモードで起動する場合は、こちら を参照して、 設定を追記してください。