Spring Boot 1.2.x の Web アプリを 1.3.x へバージョンアップする ( その8 )( excludeDevtools オプションを指定して jar ファイルには devtools を入れないようにする )
概要
- 今回の手順で確認できるのは以下の内容です。
- excludeDevtools オプションを指定して jar ファイルには devtools を入れないようにする
参照したサイト・書籍
目次
- build.gradle を変更する
- IntelliJ IDEA から起動した時には spring.thymeleaf.cache = false になることを確認する
- jar ファイルを作成して java -jar で起動した時には spring.thymeleaf.cache = true になることを確認する
- application-develop.properties, application-unittest.properties, application-product.properties からコメントアウトした設定を削除する
- 次回は。。。
手順
build.gradle を変更する
build.gradle を以下のように変更します。
bootRepackage { mainClass = 'ksbysample.webapp.lending.Application' excludeDevtools = true } dependencies { def jdbcDriver = "org.postgresql:postgresql:9.4.1208" // dependency-management-plugin によりバージョン番号が自動で設定されるもの // Appendix A. Dependency versions ( http://docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-dependency-versions ) 参照 compile("org.springframework.boot:spring-boot-starter-web") compile("org.springframework.boot:spring-boot-starter-thymeleaf") compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4") compile("org.springframework.boot:spring-boot-starter-data-jpa") compile("org.springframework.boot:spring-boot-starter-velocity") compile("org.springframework.boot:spring-boot-starter-mail") compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework.boot:spring-boot-starter-redis") compile("org.springframework.boot:spring-boot-starter-amqp") compile("org.springframework.boot:spring-boot-devtools") compile("org.springframework.session:spring-session") ..........
- dependencies タスクの上に
bootRepackage { ... }
を追加します。その中でexcludeDevtools = true
を指定して jar ファイル作成時に devtools が入らないようにします。
build.gradle 変更後、clean タスクの実行→「Rebuild Project」メニューの実行をしておきます。
IntelliJ IDEA から起動した時には spring.thymeleaf.cache = false になることを確認する
最初に IntelliJ IDEA の画面右上の「Select Run/Debug Configuration」で「Application」を選択した後、「Run」ボタンをクリックして Tomcat を起動します ( JRebel を使用せずに Tomcat が起動します )。
ちなみに「Select Run/Debug Configuration」に「Application」が表示されない場合には、Project View 上で Application クラスを選択してコンテキストメニューを表示した後、「Run 'Application'」メニューを選択して実行すれば選択肢に表示されます。
http://localhost:8080/sample/ にアクセスすると spring.thymeleaf.cache = false
と表示されることが確認できます。
Tomcat を停止します。
JRebel で Tomcat を起動した時も false と表示されるのか確認します。
IntelliJ IDEA の画面右上の「Select Run/Debug Configuration」で「Application」を選択した後、「Run with JRebel」ボタンをクリックして Tomcat を起動します。
再度 http://localhost:8080/sample/ にアクセスすると先程と同様に spring.thymeleaf.cache = false
と表示されることが確認できます。
Tomcat を停止します。
jar ファイルを作成して java -jar で起動した時には spring.thymeleaf.cache = true になることを確認する
build タスクを実行して ksbysample-webapp-lending-1.1.0-RELEASE.jar を作成します。
ksbysample-webapp-lending-1.1.0-RELEASE.jar を C:\webapps\ksbysample-webapp-lending\lib の下へコピーします。
webapp_startup.bat を実行します。
http://localhost:8080/sample/ にアクセスすると spring.thymeleaf.cache =
と表示されました。値がセットされていない時はデフォルト値なので spring.thymeleaf.cache = true
と同じです ( Appendix A. Common application properties 参照 )。
webapp_startup.bat 実行時に開いたコマンドプロンプトを閉じます。
application-develop.properties, application-unittest.properties, application-product.properties からコメントアウトした設定を削除する
これで devtools を入れても問題なさそうですので、application.properties ファイルから cache の ON/OFF を設定している部分を削除します ( 特にソースは記載しません )。
次回は。。。
他に何か対応したいものがなければ、最後に jar ファイルで実行した状態で一通り動作を確認して終了とする予定です。
ソースコード
履歴
2016/06/05
初版発行。