spring-projects / spring-projects/spring-boot

Support instance main methods

Open
#35,785 20 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: pending-design-work type: enhancement
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 for public static void main(String[] args) methods at the moment
  • MainMethodRunner, as used by our launchers, only supports running a static main(String[]) method at the moment
  • DevTools ( see MainMethod), only supports static main(String[]) methods when finding the method to use for restart at the moment

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.