When repeatedly deploying and undeploying a Spring Boot version 3.1.2 web application (WAR file) in a Tomcat application server one gets java.lang.OutOfMemoryError: Metaspace after 7-8 attempts.
This seems to be caused by the change in org.springframework.boot.SpringApplicationShutdownHook class, which now also registers org.springframework.boot.SpringApplicationShutdownHook.Handlers as a shut-down hook, which was not the case with Spring Boot 2.7 for example.