diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 05778c30c8..7fbfa7d256 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -409,9 +409,10 @@ public class SpringApplication { private void addAotGeneratedInitializerIfNecessary(List> initializers) { if (NativeDetector.inNativeImage()) { try { - Class aClass = Class.forName(this.mainApplicationClass.getName() + "__ApplicationContextInitializer", - true, getClassLoader()); - ApplicationContextInitializer initializer = (ApplicationContextInitializer) aClass + Class initializerClass = Class.forName( + this.mainApplicationClass.getName() + "__ApplicationContextInitializer", true, + getClassLoader()); + ApplicationContextInitializer initializer = (ApplicationContextInitializer) initializerClass .getDeclaredConstructor().newInstance(); initializers.add(0, initializer); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationHooks.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationHooks.java index 4c753a383d..c245388491 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationHooks.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationHooks.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.util.function.ThrowingSupplier; /** * Low-level hooks that can observe a {@link SpringApplication} and modify its behavior. @@ -33,7 +34,6 @@ final class SpringApplicationHooks { private static final ThreadLocal hooks = ThreadLocal.withInitial(Hooks::new); private SpringApplicationHooks() { - } /** @@ -44,10 +44,10 @@ final class SpringApplicationHooks { * @return the result of the action * @throws Exception if a failure occurs while performing the action */ - static T withHook(Hook hook, Action action) throws Exception { + static T withHook(Hook hook, ThrowingSupplier action) throws Exception { hooks.get().add(hook); try { - return action.perform(); + return action.getWithException(); } finally { hooks.get().remove(hook); @@ -84,7 +84,6 @@ final class SpringApplicationHooks { * @param application the application that is being run */ default void preRun(SpringApplication application) { - } /** @@ -95,7 +94,6 @@ final class SpringApplicationHooks { * @param context the application's context */ default void postRun(SpringApplication application, ConfigurableApplicationContext context) { - } /** @@ -110,24 +108,6 @@ final class SpringApplicationHooks { } - /** - * An action that can be performed with a hook attached. - *

- * For internal use only. - * - * @param the type of the action's result - */ - interface Action { - - /** - * Perform the action. - * @return the result of the action - * @throws Exception if a failure occurs - */ - T perform() throws Exception; - - } - static final class Hooks implements Hook { private final List delegates = new ArrayList<>();