From a95a7e3d40864a353fb91d956d391a4ffe93ffb6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 13 Jan 2021 10:11:56 +0000 Subject: [PATCH] Allow restart to be enabled when CL not named AppClassLoader Previously, the restart initializer that enables restart when -Dspring.devtools.restart.enabled=true is set had no effect when the ClassLoader's name did not contain AppClassLoader. This commit updates RestartApplicationListener to use the correct RestartInitializer when the system property has forcibly enabled restart. When restart is enabled a SilentExitException is thrown and it should be caught and handled by the SilentExitExceptionHandler. When the application is invoked via one of the loader's LauncherClasses reflection is used and this exception becomes wrapped in an InvocationTargetEception. Previously, this wrapping prevented SilentExitExceptionHandler from handling the exception. This commit updates the handler to look for an InvocationTargetException with a SilentExitException target in addition to continuing to look for a SilentExitException directly. Fixes gh-24797 --- .../boot/devtools/restart/RestartApplicationListener.java | 5 ++--- .../boot/devtools/restart/SilentExitExceptionHandler.java | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java index fe2f84107e6..6969c99e61a 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,12 +83,11 @@ public class RestartApplicationListener implements ApplicationListener