Forward port of issue #41678 to 3.4.x.

Comment From: wilkinsona

Duplicates https://github.com/spring-projects/spring-boot/issues/41681.