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 4e033eb9f0..f95b30320e 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 @@ -285,10 +285,10 @@ public class SpringApplication { } private Optional> findMainClass(Stream stack) { - return stack - .filter((frame) -> Objects.equals(frame.getMethodName(), "main") - && Objects.equals(frame.getMethodType(), MethodType.methodType(void.class, String[].class))) - .findFirst().map(StackWalker.StackFrame::getDeclaringClass); + MethodType mainMethodType = MethodType.methodType(void.class, String[].class); + return stack.filter((frame) -> Objects.equals(frame.getMethodName(), "main")) + .filter((frame) -> Objects.equals(frame.getMethodType(), mainMethodType)).findFirst() + .map(StackWalker.StackFrame::getDeclaringClass); } /**