Spring Boot 2.4.3 application immediately shuts down after starting

Viewed 563

Tools:

  • Sprint Boot 2.4.3
  • IntelliJ IDEA 2020.3.3 Community Edition
  • Java 15.0.2

I just create a demo project by using Spring Assistant and just turn on Spring Web dependency, the pom.xml also has

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

When I run the DemoApplication.java, application immediately shuts down after starting, not print anything about server or port:

2021-03-18 09:17:38.398  INFO 8553 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 15.0.2 on Summoring-MBP.local with PID 8553 (/Users/Smeegol/Git/demo2/target/classes started by Smeegol in /Users/Smeegol/Git/demo2)
2021-03-18 09:17:38.403  INFO 8553 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-03-18 09:17:40.286  INFO 8553 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 3.424 seconds (JVM running for 4.374)

Process finished with exit code 0

How can I make the web server running and listening port like 8080 after application started? Thanks.

Source code can be downloaded from here: https://github.com/Smeegol/SpringBootDemo/blob/main/demo.zip

2 Answers

Your code works. I do not have Java 15, I have changed it to use 11 and it runs.

This is what I have got:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.3)

2021-03-17 23:15:01.495  INFO 34616 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 11.0.3 on machine1.domain.com with PID 34616 (/Users/test/Downloads/demo 5/out/production/demo started by test in /Users/test/Downloads/demo 5)
2021-03-17 23:15:01.497  INFO 34616 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-03-17 23:15:02.192  INFO 34616 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-03-17 23:15:02.199  INFO 34616 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-03-17 23:15:02.199  INFO 34616 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-03-17 23:15:02.251  INFO 34616 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-03-17 23:15:02.251  INFO 34616 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 711 ms
2021-03-17 23:15:02.362  INFO 34616 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-17 23:15:02.495  INFO 34616 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-03-17 23:15:02.508  INFO 34616 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.249 seconds (JVM running for 1.977)

JDK 15 might be 'too new'. If you are just experimenting, downgrade JDK to a lower one. Java 11 has long-term support.

This happens when in your source code doesn't have any API listened, it means there aren't any classes marked with @RestController or @Controller anonation in your source code, SpringBoot at this time just simply build source code run and exit without returning any error messages

Related