spring-projects / spring-projects/spring-boot
Support instance main methods
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 81.5k
- Forks
- 42.7k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Description
Java 21 introduces (as a preview) support for instance main methods and for main methods (static or instance) that have no parameters:
Selecting a main method
When launching a class, the launch protocol chooses the first of the following methods to invoke:
- A
static void main(String[] args)method of non-private access (i.e., public, protected or package) declared in the launched class,- A
static void main()method of non-private access declared in the launched class,- A
void main(String[] args)instance method of non-private access declared in the launched class or inherited from a superclass, or, finally,- A
void main()instance method of non-private access declared in the launched class or inherited from a superclass.
To support these new main methods, some changes will be required in Boot:
MainClassFinder, as used by our Maven and Gradle plugins (and Antlib), only looks forpublic static void main(String[] args)methods at the momentMainMethodRunner, as used by our launchers, only supports running astatic main(String[])method at the moment- DevTools ( see
MainMethod), only supportsstatic main(String[])methods when finding the method to use for restart at the moment
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading MainClassFinder, MainMethodRunner, and DevTools' MainMethod, since the issue identifies these as the affected entry points. Check how Maven, Gradle, Antlib, launchers, and DevTools restart discover and invoke main methods. Done means supporting the listed static and instance, parameterized and no-parameter forms introduced by Java 21.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100