防止来自Spring Boot的数据库关闭命令 [英] Prevent database shutdown command from Spring Boot

查看:173
本文介绍了防止来自Spring Boot的数据库关闭命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的Spring Boot应用程序(从Intellij IDEA中)并触发该应用程序的停止,重新启动或自动重新部署时;向我的HSQLDB发出了关闭命令.

When I run my Spring Boot application (from within Intellij IDEA) and either trigger a stop, restart or automatic redeploy of the application; something is issuing a shutdown command to my HSQLDB.

我从外部终端窗口以服务器模式运行HSQLDB(v.2.3.4).

I run a HSQLDB (v.2.3.4) in Server mode from an external terminal window.

重新启动或停止Spring Boot应用程序时的HSQLDB Server日志:

HSQLDB Server log at the moment I restart or stop my Spring Boot application:

[Server@4f023edb]: Initiating shutdown sequence...
[Server@4f023edb]: Shutdown sequence completed in 101 ms.
[Server@4f023edb]: 2017-05-05 21:47:01.878 SHUTDOWN : System.exit() is called next 

这当然很烦人,因为每次重新部署应用程序时,我都要经历手动启动HSQLDB的麻烦.我该如何防止这种情况的发生或对实际情况的解释.

This is of course very annoying since I have to go through the hassle of manually bringing up my HSQLDB every time I redeploy the application. How do I prevent this from happening, or an explanation of what is actually going on.

这似乎仅在从Intellij IDEA中运行Spring Boot应用程序时发生,如果我从终端窗口启动Spring Boot application-jar并发出shutdown Ctrl + C ,那么HSQLDB不会受到影响.

This only seems to happen when running the Spring Boot application from within Intellij IDEA, if I start the Spring Boot application-jar from a terminal window and issue shutdown Ctrl+C, then HSQLDB is not affected.

推荐答案

找出为什么我仅在Intellij IDEA中运行时才遇到此问题的原因是

Turns out the reason why I only experience this problem when running from within Intellij IDEA is because spring-boot-devtools (a maven dependency included in my project) is not packaged in the application-jar that I run from a terminal window.

运行完全打包的应用程序时,将自动禁用开发人员工具.如果您的应用程序是使用java -jar启动的,或者是使用特殊的类加载器启动的,则该应用程序被视为生产应用程序".将依赖项标记为可选是一种最佳实践,它可以防止将devtools过渡使用您的项目应用于其他模块. Gradle不支持现成的可选依赖项,因此您可能希望同时查看propdeps-plugin.

Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a "production application". Flagging the dependency as optional is a best practice that prevents devtools from being transitively applied to other modules using your project. Gradle does not support optional dependencies out-of-the-box so you may want to have a look to the propdeps-plugin in the meantime.

从Intellij IDEA中运行应用程序时,

spring-boot-devtools处于活动状态,并且提供一个关闭钩子,该钩子将尝试正常关闭数据库资源(除其他外).

spring-boot-devtools is active when running the application from within Intellij IDEA and provides a shutdown hook that will try to gracefully shutdown the database resource (amongst other things).

可以通过以下方式禁用关闭挂钩;

The shutdown hook can be disabled the following way;

SpringApplication app = new SpringApplication(MyApplication.class);
app.setRegisterShutdownHook(false);  //This disables the shutdown hook
app.run(args);

此解决方案解决了我遇到的问题.

This solution resolved the problem I had.

这篇关于防止来自Spring Boot的数据库关闭命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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