Spring Boot Devtools を IntelliJ IDEA で動かす
IntelliJ IDEA にて Spring Boot Devtools の設定をした際、一向に変更が反映されず、はまってしまったので備忘録。
結論としては、こちらの記事のとおりでした。
素晴らしい記事です。
シクりポイント
- 魔法の力を信じてしまった
I am guessing you are coding and expect DevTools to auto-magically figure out you have changed something in your project? Devtools does that by watching your classpath folder(s). When a .class file (or a resource) has changed, devtools take the appopriate action.
2.レジストリの設定を知らなかった
これは何か? 公式でも出てこない気がする。。
compiler.automake.allow.when.app.running
2017/08 追記
3. main メソッドから起動しなかった
タスクランナーとして Gradle を使用していますが、アプリケーションの起動タスクとして、bootRun があります。
bootRun から起動すると、Gradle のビルド先である $projectRoot/build がリソースの変更対象として監視されるようになります。
14:42:38.506 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
14:42:38.509 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
14:42:38.509 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/Users/userName/Documents/workspace/projectName/build/classes/main/, file:/Users/userName/Documents/workspace/projectName/build/resources/main/]
しかしながら、IntelliJ IDEA にてコンパイルすると成果物は、$projectRoot/out 配下に配置されます。
$projectRoot/build 配下にリソースを配置する役目は Gradle となりますが、Gradle が動作するきっかけがありません。
このため、main メソッドからアプリケーションを起動させて、$projectRoot/out フォルダ配下を変更の監視対象にします。
14:32:12.395 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
14:32:12.398 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
14:32:12.398 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/Users/userName/Documents/workspace/projectName/out/production/classes/, file:/Users/userName/Documents/workspace/projectName/out/production/resources/]