sohatach's blog

http://github.com/soha

Spring BootでHot Reloading

Spring Bootをいじっていると、少しコードを修正しただけで、
毎回パッケージングしてjarファイルから起動とやっていると時間が掛かってとても面倒。
Spring Loadedというライブラリを使うとHot Reloadingが可能とのことのため、試してみました。

1.Spring Loadedのダウンロード

http://search.maven.org/remotecontent?filepath=org/springframework/springloaded/1.2.0.RELEASE/springloaded-1.2.0.RELEASE.jar
をダウンロードします。
現在は、1.2.0が最新のようですが、そのときの最新版を使うのが良いと思います。

2.Eclipseでの設定方法

プロジェクト右クリック → Run As → Run Configurations… → Java Application → <プロジェクト名> → Arguments

ここのVM Argumentsに以下のように設定します。

-javaagent://springloaded-1.2.0.RELEASE.jar -noverify

このようにJavaプロセスの起動時にspringloadedを介することで、Hot Reloadingが可能となるようです。

3.Thymeleafの設定

Thymeleaf(テンプレートエンジン)でHot Reloadingを行うには、上記設定だけでは足りず
application.propertiesに以下の設定が必要です。

spring.thymeleaf.cache: false

これにてHot Reloadingが可能となります。
いちいち再起動せずにコードの変更結果が確認できる。
開発するうえでこれはかなり重要です。


参考サイト

・Hot Swapping in Spring Boot with Eclipse STS
http://coderpills.wordpress.com/2014/05/21/hot-swapping-in-spring-boot-with-eclipse-sts/