question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Application does not terminate upon completion of CommandLineRunner anymore

See original GitHub issue

I run some java batch processes using this code structure:

@SpringBootApplication
public class Application {
    
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner(MyServiceInstance service) {
        return args -> {
            service.doJob();
        };
    }

}

Prior spring 2.4.2 my service/process terminates after doing it’s Job, so the code was convenient to run batch jobs. Starting from spring 2.4.2 the service instances do not terminate. So image the result all my instances are running in my AWS Batch account causing cost increases and blocking other jobs.

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
philwebbcommented, Apr 6, 2021

@eduardobarrena-tc You can already use Spring Boot without auto-configuration, if you look at @SpringBootApplication you’ll see it’s actually:

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
		@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {

If you don’t want auto-configuration you can annotate your main class with:

@SpringBootConfiguration
@ComponentScan

You can also exclude the spring-boot-autoconfigure jar if you want to be totally sure that no auto-configuration functionality is used.

1reaction
philwebbcommented, Apr 6, 2021

We’re in a bit of a catch 22. The shutdown() method does get called, but only when the ApplicationContext is closed. That won’t happen if non-daemon threads are still active.

@eduardobarrena-tc you can change your main method to this to force the context to close:

public static void main(String[] args) {
	SpringApplication.run(DemoApplication.class, args).close();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

spring boot application does not exit after all tasks are ...
First off, you are not closing the ExecutorService properly, your multiThreadTest should look like: public void multiThreadTest() throws ...
Read more >
Spring Boot Reference Guide
Try the How-to documents. They provide solutions to the most common questions. Learn the Spring basics. Spring Boot builds on many other Spring...
Read more >
Spring Command Line application doesn't terminate
The issue is that after Neo4j connectivity addition, the application no longer exits after its main() method finishes.
Read more >
Activiti User Guide
The Activiti UI application uses an in-memory H2 database by default, ... Depending on the type or event, these entities cannot be updated...
Read more >
IntelliJ does not terminate Spring Boot applications
I am using IntelliJ IDEA 2017.2.5 Ultimate on macOs 10.12.6. I have build very simple Java 1.8 command line application using Spring Boot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found