Forward port of issue #37477 to 3.1.x.

Comment From: drnesic

We tested upgrade from spring-boot 3.1.4 to 3.2.1 and this problem surfaced again, will the solution be forward ported to 3.2.x? Alternatively, is there a workaround?

Comment From: wilkinsona

The fix is in 3.2.x. If you're seeing the problem with 3.2.1, please open a new issue with a minimal example that reproduces it.