Forward port of issue https://github.com/spring-projects/spring-boot/issues/43966 to 3.4.x.