Forward port of issue #45969 to 4.0.x.

Comment From: snicoll

https://github.com/spring-projects/spring-boot/commit/7221a46d633447a53aafe030fe19dd6f3c0d1ff6