阻止来自 Spring Boot 的数据库关闭命令
Prevent database shutdown command from Spring Boot
当我 运行 我的 Spring 引导应用程序(从 Intellij IDEA 中)并触发应用程序的停止、重启或自动重新部署时;某些东西正在向我的 HSQLDB 发出关闭命令。
我 运行 来自外部终端的处于服务器模式的 HSQLDB (v.2.3.4) window。
我重新启动或停止 Spring 引导应用程序时的 HSQLDB 服务器日志:
[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 的麻烦。我如何防止这种情况发生,或者解释实际发生的情况。
这似乎只发生在 运行从 Intellij IDEA 中启动 Spring 启动应用程序时,如果我从终端启动 Spring 启动应用程序 jar window 并发出 shutdown Ctrl+C,然后 HSQLDB 不受影响。
原来我只在 Intellij IDEA 中 运行ning 时遇到这个问题的原因是因为 spring-boot-devtools(我的项目中包含的 Maven 依赖项)没有打包在应用程序 jar 中我 运行 从终端 window.
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.
spring-boot-devtools 在 运行 从 Intellij IDEA 中启动应用程序时处于活动状态,并提供一个关闭挂钩,该挂钩将尝试正常关闭数据库资源(除其他外)。
可以通过以下方式禁用关闭挂钩;
SpringApplication app = new SpringApplication(MyApplication.class);
app.setRegisterShutdownHook(false); //This disables the shutdown hook
app.run(args);
这个解决方案解决了我遇到的问题。
当我 运行 我的 Spring 引导应用程序(从 Intellij IDEA 中)并触发应用程序的停止、重启或自动重新部署时;某些东西正在向我的 HSQLDB 发出关闭命令。
我 运行 来自外部终端的处于服务器模式的 HSQLDB (v.2.3.4) window。
我重新启动或停止 Spring 引导应用程序时的 HSQLDB 服务器日志:
[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 的麻烦。我如何防止这种情况发生,或者解释实际发生的情况。
这似乎只发生在 运行从 Intellij IDEA 中启动 Spring 启动应用程序时,如果我从终端启动 Spring 启动应用程序 jar window 并发出 shutdown Ctrl+C,然后 HSQLDB 不受影响。
原来我只在 Intellij IDEA 中 运行ning 时遇到这个问题的原因是因为 spring-boot-devtools(我的项目中包含的 Maven 依赖项)没有打包在应用程序 jar 中我 运行 从终端 window.
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.
spring-boot-devtools 在 运行 从 Intellij IDEA 中启动应用程序时处于活动状态,并提供一个关闭挂钩,该挂钩将尝试正常关闭数据库资源(除其他外)。
可以通过以下方式禁用关闭挂钩;
SpringApplication app = new SpringApplication(MyApplication.class);
app.setRegisterShutdownHook(false); //This disables the shutdown hook
app.run(args);
这个解决方案解决了我遇到的问题。