1
votes

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.

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

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 

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.

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.

1

1 Answers

3
votes

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.

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 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.