Terminating mvn spring-boot:run doesn't stop tomcat

后端 未结 18 1253
别那么骄傲
别那么骄傲 2020-12-04 07:11

I can successfully start spring-boot with mvn spring-boot, the documentation mentions to gracefully exit the application hit ctrl-c.



        
相关标签:
18条回答
  • 2020-12-04 07:50

    It still happens to me on version 1.1.9 running on windows 7.

    So after hitting Ctrl C. The fastest way to kill the background java will be .

    Find the java PID

         c:\>netstat -ano | find "8080"
         TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       1196
         TCP    [::]:8080              [::]:0                 LISTENING       1196
         c:\>taskkill /F /PID 1196
         SUCCESS: The process with PID 1196 has been terminated.
    

    I am assuming in the example above that you are running on http port 8080

    For Mac Users:

         $lsof -i :8080
         COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
         java    SOME_PID user  417u  IPv6 0xa4b3be242c249a27      0t0  TCP *:name (LISTEN)
         kill -9 SOME_PID
    
    0 讨论(0)
  • 2020-12-04 07:51

    In IDEA you have to Stop process before Run it again. That command will shut down embedded Tomcat.

    0 讨论(0)
  • 2020-12-04 07:54

    I've had this problem when running spring boot app from netbeans 8.1 on Mac. The java process was not terminated when I hit red square button in netbeans so when I relaunched the app I always get "bind exception, adress already in use" thing. This is known bug.

    The solution was to add spring-boot:run command to run goals of project...

    ...and also if you get "No plugin found for prefix 'spring-boot' in the current project and in the plugin groups" you might need to add this to dependencies:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
    </parent>
    
    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
    
    0 讨论(0)
  • 2020-12-04 07:54

    You cause a shutdown by calling curl -v -X POST http://127.0.0.1:8091/shutdown provided you configured spring-boot properly.

    To support this you will have to update your application properties. This is partially described in https://stackoverflow.com/a/26563344/58794 .

    updating application.yml by adding:

    management:
      security:
        enabled: false
    endpoints:
      shutdown:
        enabled: true
    

    or updating application.properties by adding:

    management.security.enabled=false
    endpoints.shutdown.enabled=true
    

    Once called

    $ curl -v -X POST http://127.0.0.1:8091/shutdown
    * STATE: INIT => CONNECT handle 0x600057990; line 1423 (connection #-5000)
    * Added connection 0. The cache now contains 1 members
    *   Trying 127.0.0.1...
    * TCP_NODELAY set
    * STATE: CONNECT => WAITCONNECT handle 0x600057990; line 1475 (connection #0)
    * Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0)
    * STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x600057990; line 1592 (connection #0)
    * Marked for [keep alive]: HTTP default
    * STATE: SENDPROTOCONNECT => DO handle 0x600057990; line 1610 (connection #0)
    > POST /shutdown HTTP/1.1
    > Host: 127.0.0.1:8091
    > User-Agent: curl/7.56.1
    > Accept: */*
    >
    * STATE: DO => DO_DONE handle 0x600057990; line 1689 (connection #0)
    * STATE: DO_DONE => WAITPERFORM handle 0x600057990; line 1814 (connection #0)
    * STATE: WAITPERFORM => PERFORM handle 0x600057990; line 1824 (connection #0)
    * HTTP 1.1 or later with persistent connection, pipelining supported
    < HTTP/1.1 200
    < X-Application-Context: application:h2:8091
    < Content-Type: application/vnd.spring-boot.actuator.v1+json;charset=UTF-8
    < Transfer-Encoding: chunked
    < Date: Fri, 22 Dec 2017 07:01:04 GMT
    <
    * STATE: PERFORM => DONE handle 0x600057990; line 1993 (connection #0)
    * multi_done
    * Connection #0 to host 127.0.0.1 left intact
    * Expire cleared
    {"message":"Shutting down, bye..."}
    

    the container will shutdown

    o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
    o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
    j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
    

    but if you launched from mvn spring-boot:run you will likely get a:

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 35.613 s
    [INFO] Finished at: 2017-12-22T02:01:05-05:00
    [INFO] Final Memory: 25M/577M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.7.RELEASE:run (default-cli) on project PROJECTNAME: Could not exec java: Application finished with exit code: 1 -> [Help 1]
    

    If you do not have management.security.enabled=false you may be presented with the following error:

    $ curl -v -X POST http://127.0.0.1:8091/shutdown
    > POST /shutdown HTTP/1.1
    > Host: 127.0.0.1:8091
    > User-Agent: curl/7.56.1
    > Accept: */*
    >
    < HTTP/1.1 401
    < X-Application-Context: application:h2:8091
    < Content-Type: application/vnd.spring-boot.actuator.v1+json;charset=UTF-8
    < Transfer-Encoding: chunked
    < Date: Fri, 22 Dec 2017 06:56:19 GMT
    <
    {"timestamp":1513925779265,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/shutdown"}
    

    If you do not have endpoints.shutdown.enabled=true you will see:

    $ curl -v -X POST http://127.0.0.1:8091/shutdown
    > POST /shutdown HTTP/1.1
    > Host: 127.0.0.1:8091
    > User-Agent: curl/7.56.1
    > Accept: */*
    >
    < HTTP/1.1 404
    < X-Application-Context: application:h2:8091
    < Content-Type: application/json;charset=UTF-8
    < Transfer-Encoding: chunked
    < Date: Fri, 22 Dec 2017 06:58:52 GMT
    <
    {"timestamp":1513925932345,"status":404,"error":"Not Found","message":"No message available","path":"/shutdown"}
    

    If you try a GET instead of POST this error will be presented:

    $ curl -v http://127.0.0.1:8091/shutdown
    > GET /shutdown HTTP/1.1
    > Host: 127.0.0.1:8091
    > User-Agent: curl/7.56.1
    > Accept: */*
    >
    < HTTP/1.1 405
    < X-Application-Context: application:h2:8091
    < Allow: POST
    < Content-Type: application/json;charset=UTF-8
    < Transfer-Encoding: chunked
    < Date: Fri, 22 Dec 2017 06:54:12 GMT
    <
    {"timestamp":1513925652827,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'GET' not supported","path":"/shutdown"}
    
    0 讨论(0)
  • 2020-12-04 07:54

    Type the following commands in order.

    $ ps -ef | grep -i java
    $ kill -9 3361
    
    0 讨论(0)
  • 2020-12-04 07:55

    Edit: in ubuntu, use the command:

    fuser -k 8080/tcp
    

    to kill the process. I'm using spring-boot 1.3.0-Build-snapshot and the problem still persist. My SO is Ubuntu and the problem occurs either running from Eclipse or from the console. The discussion about this issue is here. This seems to be an issue with spring-boot libraries, at least concerning tomcat libraries. I'm also in the line for the this fix. Unfortunately this is the price we pay for trying to use cutting edge technologies until they get matured.

    0 讨论(0)
提交回复
热议问题