SpringBootを2.0.1.RELEASEから2.6.6にバージョンアップしてみた

数年前に他で作られたものを引き継いで担当しているSpringBootアプリがあるのですが、dependency-checkを実行するとライブラリに多数の脆弱性がある事が判明。

[ERROR] dom4j-1.6.1.jar: CVE-2020-10683(9.8)
[ERROR] hibernate-core-5.2.16.Final.jar: CVE-2019-14900(6.5), CVE-2020-25638(7.4)
[ERROR] hibernate-validator-6.0.9.Final.jar: CVE-2019-10219(6.1), CVE-2020-10693(5.3)
略

対応の時間が取れそうなので、spring-boot-starterを対応開始時点最新だった2.6.4へ一気に上げてみる事にしました。今回対象のアプリではごく一部だけコード変更が必要でしたが、それを書き直して実行してみると、、起動に失敗しているようです。

***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
   processorLookupService (field private jp.esoro.automation.application.impl.xxxx)
      ↓
   monitoringAlert (field private jp.esoro.automation.application.ApplicationEvents xxxx)
┌─────┐
|  applicationEventsImpl (field private jp.esoro.automation.application.NotificationLookupService xxxx)
↑     ↓
|  notificationLookupService (field jp.esoro.automation.application.impl.ChangeNotification xxxx)
↑     ↓
|  changeNotification (field private jp.esoro.automation.application.ApplicationEvents xxxx)
└─────┘
Action:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

下記にも出てましたが、メッセージの図が示している通り循環参照をしているようです。
[blogcard url=”https://qiita.com/rhirabay/items/c3fe7cd7faee9f35ab2c”]

該当箇所のコードを読み、そのままで問題無い事を確認した上でメッセージの通りにapplication.ymlに設定を追加します。

  spring:
    main:
      allow-circular-references: true

稼働確認をしていくと数か所の動作に問題がありましたが、基本的にはライブラリ間のバージョン不一致によるものだったので、使用ライブラリの依存を整理してバージョンを調整。

対応が殆ど終わったと思ったら、Springの脆弱性「Spring4Shell」が見つかり、実行環境的にはJava1.8なので影響は無いのですが、最新の2.6.6にして再度稼働確認し一段落。

カテゴリー: Spring Boot   作成者: bokusui パーマリンク

bokusui について

ソフトウェアハウスでのPG・SEから始まり、10年近く勤めた金融系企業の社内SEを数年前にやめ、フリーランス時代を経たのち法人成りしました。システム開発の全工程をこじんまりとやり続けています。