Skip to content

Commit 68fc87b

Browse files
committed
Merge pull request #31828 from quaff
* gh-31828: Polish "Take MethodType into account to deduce main application class" Take MethodType into account to deduce main application class Closes gh-31828
2 parents add7205 + b9b2564 commit 68fc87b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot;
1818

1919
import java.lang.StackWalker.StackFrame;
20+
import java.lang.invoke.MethodType;
2021
import java.time.Duration;
2122
import java.util.ArrayList;
2223
import java.util.Arrays;
@@ -165,6 +166,7 @@
165166
* @author Brian Clozel
166167
* @author Ethan Rubinson
167168
* @author Chris Bono
169+
* @author Yanming Zhou
168170
* @since 1.0.0
169171
* @see #run(Class, String[])
170172
* @see #run(Class[], String[])
@@ -283,7 +285,9 @@ private Class<?> deduceMainApplicationClass() {
283285
}
284286

285287
private Optional<Class<?>> findMainClass(Stream<StackFrame> stack) {
286-
return stack.filter((frame) -> Objects.equals(frame.getMethodName(), "main")).findFirst()
288+
MethodType mainMethodType = MethodType.methodType(void.class, String[].class);
289+
return stack.filter((frame) -> Objects.equals(frame.getMethodName(), "main"))
290+
.filter((frame) -> Objects.equals(frame.getMethodType(), mainMethodType)).findFirst()
287291
.map(StackWalker.StackFrame::getDeclaringClass);
288292
}
289293

0 commit comments

Comments
 (0)