spring-guides / gs-consuming-rest

Consuming a RESTful Web Service :: Learn how to retrieve web page data with Spring's RestTemplate.
https://spring.io/guides/gs/consuming-rest/
Apache License 2.0
195 stars 287 forks source link

Close down tomcat gracefully after completion of application. #22

Closed jessewriter closed 7 years ago

jessewriter commented 8 years ago

After running this application a second time i get the following errors:

Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.

Caused by: java.net.BindException: Address already in use Caused by: org.apache.catalina.LifecycleException: service.getName(): "Tomcat"; Protocol handler start failed

There is no discussion on how to close down tomcat. Looking in the server window of Spring Tool Suite shows a tomcat server that is not running and not used by the application (obviously since its an embedded server). So you can not stop it there. I did find that I could stop the application clicking the red square showing in the attached image and then run the application again without error. I believe there should be a better way to run this application and shut it down gracefully. sts stop application

dsyer commented 8 years ago

I don't think there is a better way. If you run it in the IDE, then the IDE has a way to stop it running. I think documenting IDE features is mostly out of scope for these guides (we try to cover everything but there are too many variants), and actually they only tell you how to do it on the command line, which then blocks a terminal so you have to kill the process to stop it. Maybe some extra words in this guide would have helped you: https://spring.io/guides/gs/intellij-idea/? Did you use it?

morganwu277 commented 7 years ago

Are you using a spring-boot-starter-web dependency?

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

@jessewriter

if yes, you can have 2 options:

  1. set it as a non-web-environment, please see my repo here gs-consuming-rest
  2. use the spring-boot-starter dependency
dsyer commented 7 years ago

Yeah. There's no Tomcat dependency in this project anyway. Closing.