当使用ehcache部署Spring启动应用程序时,Tomcat不会关闭 [英] Tomcat not shutting down when Spring boot app is deployed with ehcache

查看:351
本文介绍了当使用ehcache部署Spring启动应用程序时,Tomcat不会关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对tomcat有一个奇怪的问题,我在tomcat上部署了一个spring boot应用程序(Stand alone not embedded)。我能够成功启动tomcat,它可以解决任何问题。但是当我运行shutdown(调用shutdown.sh脚本)时,它显示连接被拒绝。我试过这个

I have strange problem with tomcat, I have a spring boot application deployed on tomcat(Stand alone not embedded). I am able to start tomcat successfully and it is working fine with out any issues. But when I run shutdown(invoking shutdown.sh script) it is showing connection refused. I have tried out this

Tomcat不会停止。我该如何调试?,但不能解决我的问题。我已经尝试删除我的春季启动应用程序,它可以解决任何问题。我能够启动和停止tomcat。经过进一步分析后,我发现这是因为在spring boot应用程序中配置了ehache。需要配置ehcache的关闭监听器,在春季启动时最好的方法是什么。

Tomcat doesn't stop. How can I debug this?, but does not solve my problem. I have tried removing my spring boot application and it is working fine with out any issues. I am able to start and stop tomcat. After further analysis I could find it is because of the ehache configured in spring boot application. The shutdown listener of ehcache need to configured, what is best way to do that in spring boot.

我也试过这个选项。

如何以正确的方式关闭Spring Boot应用程序?

./shutdown.sh
Using CATALINA_BASE:   /app/tomcat/myapp
Using CATALINA_HOME:   /app/tomcat/myapp
Using CATALINA_TMPDIR: /app/tomcat/myapp/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_71
Using CLASSPATH:   

    /app/tomcat/myapp/bin/bootstrap.jar:/app/tomcat/myapp/bin/tomcat-juli.jar
    Oct 18, 2016 5:36:33 AM org.apache.catalina.startup.Catalina stopServer
  SEVERE: Could not contact localhost:8005. Tomcat may not be running.
Oct 18, 2016 5:43:31 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at java.net.Socket.<init>(Socket.java:434)
        at java.net.Socket.<init>(Socket.java:211)
        at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:476)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:408)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:497)

#-> netstat -anpl|grep -i 8005
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      21668/java

我不确定为什么会这样?知道为什么会这样吗?为什么它无法收听关机端口?还为什么关闭端口有127.0.0.1?而其他进程没有吗?

I am not sure why this is happening? Any idea why this would happen? Why it is not able to listen to shutdown port? also why shut port has 127.0.0.1? while other process do not have it?

我试图telnet到端口并且正在连接

I tried to do a telnet to the port and it is connecting

telnet 127.0.0.1 8005
 Trying 127.0.0.1...
 Connected to 127.0.0.1.
 Escape character is '^]'.

知道为什么会出现问题。

Any idea why this will be an issue.

--------更新

--------Update

当我们使用ehcache作为独立部署spring boot app时,我发现这种情况正在发生。必须调用ehcache关闭钩子....春季启动时最好的方法是什么?

I have figured out this is happening when we deploy spring boot app with ehcache as standalone. The ehcache shutdown hook has to be called....What is the best way to do that in spring boot?

推荐答案

通过默认情况下,Spring Boot应用程序配置为独立运行。

By default, Spring Boot applications are configured to run standalone.

如果要在Application Server(如Tomcat)中运行,首先需要删除嵌入式容器依赖项,以防止任何冲突或争用。您可以在此处找到一个很好的指南。

If you want to run inside an Application Server (like Tomcat), the first thing you need to do is remove the embedded container dependencies to prevent any conflicts or contention. You can find a nice guide on how to do that here.

如果你已经这样做并且仍然有问题,那就意味着你在Application Server中运行了非守护程序线程(阻止它终止)。您可以使用 jstack 来识别这些,然后编写自己的 ServletContextFinalizer 以优雅地停止 contextDestroyed 上的这些线程。

If you've done that and are still having issues, it means you have non-daemon threads left running inside the Application Server (which prevent it from terminating). You can use jstack to identify these and then write your own ServletContextFinalizer to gracefully stop these threads on contextDestroyed.

这篇关于当使用ehcache部署Spring启动应用程序时,Tomcat不会关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆