2

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

Smeegol
  • 2,014
  • 4
  • 29
  • 44
  • Do you define any controllers? I'm not familiar with Spring Assistant, but Spring Initializr would give you one by default. – chrylis -cautiouslyoptimistic- Mar 18 '21 at 01:54
  • Where is it shutting down? I dont see any errors! – Phenomenal One Mar 18 '21 at 02:41
  • Please use "debug=true" to see all logs.It might show why application is getting shut down and change the port from default one.I know the application is coming up for sometime hence port might not be issue.But I replicated the scenario my side but didn't find the problem.Controller is not required to keep the application running.If the problem still persist ,Please change the jdk . – Girija Sankar Panda Mar 18 '21 at 02:50
  • @chrylis-cautiouslyoptimistic- I have create a new controller, but doesn't make any sense. Source code has been uploaded on GitHub – Smeegol Mar 18 '21 at 02:50
  • @MaruthiAdithya But no logs indicating the web server is running or listening port like 8080, it just run ok and exit with code 0 immediately – Smeegol Mar 18 '21 at 03:02

2 Answers2

1

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.

Igor Kanshyn
  • 867
  • 6
  • 13
0

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

Do Trung Duc
  • 396
  • 3
  • 13
  • I went through your source code on github and noticed that HelloController class exists. Are you sure what you use to run and what you post to github is the same – Do Trung Duc Mar 18 '21 at 03:06
  • Yes I am sure, they are totally same – Smeegol Mar 18 '21 at 03:13
  • @Smeegol I don't know for what reason but your code runs on my machine, everything works perfectly – Do Trung Duc Mar 18 '21 at 03:19
  • @Smeegol I think the problem might come from your IDE, you try to find a way to refresh or reload the project from your IDE or simply try to open the terminal and run mvn spring-boot: run – Do Trung Duc Mar 18 '21 at 03:21
  • SpringBoot application without any controllers will start and listen on a port anyways. – Igor Kanshyn Mar 18 '21 at 03:22
  • @IgorKanshyn So I created HelloController class later to retry, but it didn't make any sense – Smeegol Mar 18 '21 at 03:24
  • @Smeegol sorry, I am using VSCode and using Terminal to run it – Do Trung Duc Mar 18 '21 at 03:27
  • @Igor Kanshyn No, If you create a new project with spring initializr and then run without editing anything, SpringBoot simply builds and then exit without returning an error message. – Do Trung Duc Mar 18 '21 at 03:30
  • @Smeegol you can try hawkeye's guide in https://stackoverflow.com/questions/24439818/intellij-cannot-load-sources-from-local-maven-repository – Do Trung Duc Mar 18 '21 at 03:32