Spring Boot 2.6 以降で「The dependencies of some of the beans in the application context form a cycle」と出て起動しない

Spring Boot のバージョンを上げたところ、コードは何も変えていないのに、起動時に次のエラーが出るようになりました。 *************************** APPLICATION FAILED TO START *************************** Description: The dependencies of some of the beans in the application context form a cycle: ┌─────┐ | inventoryService (field private com.example.demo.OrderService com.example.demo.InventoryService.orderService) ↑ ↓ | orderService (field private com.example.demo.InventoryService com.example.demo.OrderService.inventoryService) └─────┘ 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. 結論:Spring Boot 2.6 から、Bean 同士の循環参照が既定で禁止されました。 2.5 までは Spring が自動で循環を解決していたので、昔から循環していたコードがバージョンアップで表に出ます。設定で以前の動きに戻せますが、本来は循環そのものをなくします。 ...

2026年10月15日 · 4 分 · もぐらび