Spring Boot app shuts down automatically

Answered

I have a Spring Boot project created in STS and then imported into IntelliJ IDEA. When I run the project by right-clicking the App.java file and clicking "Run 'App'", the project starts and then shuts down automatically without throwing any errors.

. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.3.RELEASE)

2016-05-06 23:23:10.723 INFO 19627 --- [ restartedMain] u.m.d.App : Starting App on Martys-MacBook-Air.local with PID 19627 (/Users/marty/Workspace/msr/target/classes started by marty in /Users/marty/Workspace/msr)
2016-05-06 23:23:10.734 INFO 19627 --- [ restartedMain] u.m.d.App : No active profile set, falling back to default profiles: default
2016-05-06 23:23:11.473 INFO 19627 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5f312077: startup date [Fri May 06 23:23:11 EDT 2016]; root of context hierarchy
2016-05-06 23:23:13.282 INFO 19627 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'integrationTaskExecutor'
2016-05-06 23:23:19.618 INFO 19627 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2016-05-06 23:23:19.696 INFO 19627 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-05-06 23:23:19.715 INFO 19627 --- [ restartedMain] us.markable.dev.App : Started App in 9.84 seconds (JVM running for 11.604)
2016-05-06 23:23:19.719 INFO 19627 --- [ Thread-8] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5f312077: startup date [Fri May 06 23:23:11 EDT 2016]; root of context hierarchy
2016-05-06 23:23:19.724 INFO 19627 --- [ Thread-8] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2016-05-06 23:23:19.726 INFO 19627 --- [ Thread-8] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'integrationTaskExecutor'
Disconnected from the target VM, address: '127.0.0.1:50647', transport: 'socket'

Process finished with exit code 1

I am able to run the project without any problems in STS. Can anyone help me understand why the project is shutting down automatically when started in IntelliJ? I'm using IntelliJ IDEA Ultimate 2016.1.

App.java simply has a boilerplate main() method.

@SpringBootApplication
public class App {

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

9 comments
Official comment

In 2018.1 there is new option "Include dependencies with "Provided" scope" in run configuration, please check it to include Tomcat deps.

The app will shut down if it has nothing to do. If you add at least one controller, it will keep running:

@RestController
class GreetingController {

@RequestMapping("/hello/{name}")
String hello(@PathVariable String name) {
return "Hello, " + name + "!";
}
}
-1

Thanks for the suggestion, Serge. My colleague actually found the root cause, which was a Tomcat dependency in pom.xml. Specifically, the problem was caused by the "provided" scope in this dependency.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

Removing the scope property fixed the problem and allowed the embedded Tomcat server to start normally.

1

Hi Marty and colleague,

 

Thanks.  I have started playing with Spring Boot this morning and this was the first problem that I ran into. 

 

Like you said (for gradle) - the following fixes it (it seems to be working)... but further testing may reveal issues later?

    compile('org.springframework.boot:spring-boot-starter-tomcat')
// providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
-1

The issue in the downline - and this is quite obvious - is that tomcat embedded and its jars are put in the war artifact. 

The providedRuntime mentioned above is part of the template put down by IntelliJ - but unless there is another workaround I definitely experience the same issue as Marty.  Again - I am brand new fresh to Spring Boot - so if my comments are whack then just ignore.

Gawie

0

Thanks Marty Chang for your answer from May 16, 2016 20:59. It helped me perfectly

 
 
 
0

I'm trying out the brand new IntelliJ 2018 and I'm very surprised that IntelliJ can't start a SpringBoot application cleanly without breaking the configuration.

The configuration was created by Spring Initializr and is therefore 100% correct.

configurations {
providedRuntime
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

Both Gradle bootRun and Eclipse Run as JavaApplication work, only the Java application from IntelliJ does not.

The suggestion to damage the configuration and change provided to compile is a bad solution.

Since this has already been described here in 2016, I wonder why this has not been fixed long ago?

I am looking forward to an answer, which will have a big influence on my IntelliJ evaluation.

0

Yann Cebron: Your hint was good. The application now does not stop but continues to work.

I'm not quite sure if this feature is stable yet, because when I tested it a few days ago, I had the problematic behavior, which is why I wrote a comment here.
Today I reopened the test project, checked the Run Configuration, saw that it was set correctly. Then I started the Java application and this time it worked as expected.

0

Please sign in to leave a comment.