spring-projects / spring-projects/spring-boot

Dev tools causes misconfigured command-line application to exit with 0

Open
#28,541 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: pending-design-work type: bug
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

I have a really simple spring application that's misconfigured:

@SpringBootApplication()
public class SimpleApplication implements CommandLineRunner {
    public static void main(String[] args) {
        var ctx = SpringApplication.run(SimpleApplication.class, args);
        System.exit(SpringApplication.exit(ctx));
    }

    public static class MyObject {}
    
    //Oops - No bean provided!!!
    @Autowired MyObject myObject;

    @Override public void run(String... args) { }
}

I get the following error (in intellij):

...
Consider defining a bean of type 'test.app.SimpleApplication$MyObject' in your configuration.


Process finished with exit code 1

Which is what I'd expect.

If I add the spring-boot-devtools dependency in maven:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

Then I get the following:

...
Consider defining a bean of type 'test.app.SimpleApplication$MyObject' in your configuration.


Process finished with exit code 0

It seems that adding this package causes spring boot to have the wrong return codes.

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 with the SpringApplication.run and SpringApplication.exit flow in the provided CommandLineRunner example, comparing behavior with and without spring-boot-devtools. Reproduce the missing-bean failure in both configurations and trace how the exit code is determined; done means the misconfigured application returns the expected nonzero code in both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.