Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot tomcat termination

I have exactly the same issue like that one: Terminating mvn spring-boot:run doesn't stop tomcat

The answer there says that it only happens on Windows but it's not actually true. I'm running spring boot on OSX with Intellij and when I stop the spring boot application the embedded tomcat is still running. The is the simple sample app from spring boot tutorial. Any solutions?

like image 637
kazuar Avatar asked May 08 '14 21:05

kazuar


3 Answers

i have exactly the same issue within intellij on MAC (spring boot 1.1.6.RELEASE).

i worked around it by using spring boot actuator which offers a rest endpoint (Post) to shutdown the app:

localhost:port/shutdown

this can be called by commandline: e.g. curl -X POST localhost:port/shutdown

to enable spring boot actuator add the following compile dep:

org.springframework.boot:spring-boot-starter-actuator

i created a gradle task bootStop which does run this cmd for me. you could do the same in maven or you can just call it from cmd line (also trough the intellij terminal)

Especially if you want to use debugging, you should wrap the curl cmd given above in a gradle/maven task.

See working example (gradle) here

like image 164
dasAnderl ausMinga Avatar answered Oct 15 '22 04:10

dasAnderl ausMinga


Here is a maven example for spring boot actuator to configure HTTP endpoint to shutdown a spring boot web app:

1.Maven Pom.xml:

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

2.application.properties:

#No auth  protected 
endpoints.shutdown.sensitive=false

#Enable shutdown endpoint
endpoints.shutdown.enabled=true

All endpoints are listed here:

3.Send a post method to shutdown the app:

curl -X POST localhost:port/shutdown
like image 3
JaskeyLam Avatar answered Oct 15 '22 02:10

JaskeyLam


I have met the same issue and as result I had to review all solutions on this page and related one. No one is good for me. That is why I have made small research and it is appeared that problems with captured TCP port happen just because neither Gradle nor mvn knows nothing about child manipulation with TCP port.

So instead of killing process just use command:

$ gradlew –stop 

(I hope the same exists for mvn)

This command gracefully closes daemons started by Gradle and frees captured by Tomcat ports.

like image 1
Dewfy Avatar answered Oct 15 '22 04:10

Dewfy