かんがるーさんの日記

最近自分が興味をもったものを調べた時の手順等を書いています。今は Spring Boot をいじっています。

Spring Boot 2.1.x の Web アプリを 2.2.x へバージョンアップする ( その5 )( Release Notes を見て必要な箇所を変更する )

概要

記事一覧はこちらです。

Spring Boot 2.1.x の Web アプリを 2.2.x へバージョンアップする ( その4 )( Spring Boot を 2.1.11 → 2.2.2 へバージョンアップする ) の続きです。

参照したサイト・書籍

  1. Javaパフォーマンスチューニング基礎
    https://www.slideshare.net/setoazusa/tuning-28987271

    • -XX:TieredStopAtLevel=1 オプションについて記載されています。
  2. Inspection when calling a @Bean method directly in a @Configuration where proxyBeanMethods is disabled
    https://youtrack.jetbrains.com/issue/IDEA-208951?_ga=2.42061037.931272388.1574489375-1608831281.1569753226

目次

  1. モジュールが com.sun.mail:jakarta.mail に変わっても package はまだ javax.mail でした
  2. Freemarker のテンプレートの拡張子を *.ftl*.ftlh に変更する
  3. 開発環境で Web アプリを起動する時には -XX:TieredStopAtLevel=1 オプションを指定する
  4. logging.filelogging.file.name に変更する
  5. メモ書き

手順

モジュールが com.sun.mail:jakarta.mail に変わっても package はまだ javax.mail でした

Spring Boot 2.2 Release Notes - Jakarta EE dependenciescom.sun.mail:javax.mailcom.sun.mail:jakarta.mail に変更したとの記述がありました。

gradlew dependencies を実行してみると確かに spring-boot-starter-mail が依存しているモジュールが com.sun.mail:jakarta.mail に変わっています。

+--- org.springframework.boot:spring-boot-starter-mail -> 2.2.2.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:2.2.2.RELEASE (*)
|    +--- org.springframework:spring-context-support:5.2.2.RELEASE (*)
|    \--- com.sun.mail:jakarta.mail:1.6.4
|         \--- com.sun.activation:jakarta.activation:1.2.1

ということは package も javax.mail.~jakarta.mail.~ に変更されるのかな?と思いましたが、こちらはまだ javax.mail.~ のままでした。

f:id:ksby:20191231203109p:plain

Freemarker のテンプレートの拡張子を *.ftl*.ftlh に変更する

Spring Boot 2.2 Release Notes - Freemarker templates configurationFreemarker のテンプレートの拡張子が *.ftl*.ftlh に変更されたとの記述があったので、以下のファイルの拡張子を変更します。

  • src/main/resources/templates/mail/mail001-body.ftlh
  • src/main/resources/templates/mail/mail002-body.ftlh
  • src/main/resources/templates/mail/mail003-body.ftlh

Web アプリを起動して拡張子を変更したテンプレートでメールが送信されることを確認します。

f:id:ksby:20191231211049p:plain

開発環境で Web アプリを起動する時には -XX:TieredStopAtLevel=1 オプションを指定する

Spring Boot 2.2 Release Notes - Performance improvements に以下の記述がありました。

When launching an application at development time with bootRun in Gradle or spring-boot:run in Maven, the JVM will be configured with flags (-Xverify:none and -XX:TieredStopAtLevel=1) to optimise it for reduced launch time. When running on JDK 13 -Xverify:none is not specified as it has been deprecated.

Javaパフォーマンスチューニング基礎 によると 64bit 版の VM でも最初は Client VM になるオプションとのことでした。

実際に IntelliJ IDEA のメインメニューから「Run」-「Edit Configurations...」を選択して「Run/Debug Configurations」ダイアログを開き、Spring Boot のアプリケーションの「VM options」の設定に -XX:TieredStopAtLevel=1 オプションを指定した時と指定していない時の Root WebApplicationContext: initialization completed in ... ms のメッセージに表示される時間を比較してみます。

指定していない時は 5174、4995、5422、5253、5277 でした。

指定した時は 3414、5198、5496、5110、3590 でした。

必ず速くなる訳ではないようですが、速い時には 1.5 秒程度起動時間が短くできるようです。注意が必要なオプションという訳でもないようなので、指定するようにします。build.gradle の bootRun の設定にも追加します。

bootRun {
    jvmArgs = jvmArgsForTask +
            [
                    "-Dspring.profiles.active=develop",
                    "-XX:TieredStopAtLevel=1"
            ]
}

logging.filelogging.file.name に変更する

Spring Boot 2.2 Release Notes - Deprecations in Spring Boot 2.2 に記述があったので、src/main/resources/application-product.properties 内の設定を logging.filelogging.file.name に変更します。また使用しなくなった slowquery.logging.file の設定が残っていたので削除します。

server.tomcat.basedir=D:/webapps/ksbysample-webapp-lending
logging.file.name=${server.tomcat.basedir}/logs/ksbysample-webapp-lending.log

メモ書き

  • Spring Boot 2.2 Release Notes - Performance improvements@Configuration アノテーションproxyBeanMethods=false が指定できるようになったとの記述があり、追加すると起動時間とメモリ使用量を削減できるとのことなのですが、 Inspection when calling a @Bean method directly in a @Configuration where proxyBeanMethods is disabled には If you disable proxyBeanMethods , the proxy is no longer created and calling the method simply invokes it again (here returning a new instance every time so you have no guarantee you're actually injecting the corresponding bean in the context). という記述がありました。

    GitHub の Spring Boot のレポジトリで proxyBeanMethods=false で検索すると、シンプルに new して return する Bean の場合には何でも指定されているように見えます。Spring Boot 2.2 からどうもそういう方針のようです。

    今回 Web アプリの方には追加しませんが、覚えておきましょう。

  • Logback max historylogback-spring.xml で設定している <maxHistory> の設定を logging.file.max-history で設定できるようになったという記述がありますが、変更する必要性を感じなかったので logback-spring.xml に残しました。

履歴

2019/12/31
初版発行。