Back in June 2015, Phil Webb of the Spring Boot team announced Spring Boot DevTools, coming in Spring Boot 1.3. Admittedly, I’m a bit late to the game here, so this post explores my first look into Spring Boot DevTools and how it applies to my workflow.
By simply adding a dependency for spring-boot-devtools, you get a lot of features out of the gate.
Quick benchmark of Automatic restarts and LiveReload
Probably the most useful features are automatic restarts and the embedded LiveReload server. You’ll want to get yourself a browser extension for LiveReload, here’s a link if you use Chrome. This is by no means an extensive benchmark, it’s merely my own comparison between doing things manually, vs letting DevTools do it.
I wrote a small test application with 1 endpoint, a database and spring security that just returns the results of a database query. Making a change to my code, it took about 8 seconds for the app to restart and the live reload to trigger. Contrast that to manual restarts with no live reload, it took about 19 seconds from the moment I clicked the restart button in IntelliJ and finally manually refreshed my browser. That might not seem like much on this small app, but consider the time you’ll likely save on a larger application with many more classes, database entities, resources, etc. Compound that with the amount of times you likely need your app to restart during development and the time lost grows exponentially.
One caveat if you’re an IntelliJ user like me, you’ll need to enable “Make project automatically” in the compiler preferences for automatic restarts to work.
You’ll also need to enable the
compiler.automake.allow.when.app.running registry setting in IntelliJ. You can access the registry in IntelliJ using the shortcut
Shift+Command+A, then searching for
The alternative to enabling these features is manually calling Make Project using
Command+F9, or from the menus, Build > Make Project. Which option you choose is a matter of preference, but I like it being automatic.
Experience with front end build tools may vary
There’s many build tools out there. I’ve used Grunt, Gulp + Browserify, and I’m now fiddling with Webpack. All these tools come with options for watching your front end source code and rebuilding or rebundling your code automatically. This is a handy timesaver. Combine this with Spring Boot DevTools and you’ve got a pretty streamlined workflow. My experience so far however, has been mixed.
My test application uses a Webpack build. I have
webpack --watch looking at my source and rebundling when something changes. Having IntelliJ and my browser open side by side, making a change to my front end results in my browser refreshing, but my changes aren’t always reflected, it’s hit and miss. The only way I’ve managed to get it to work consistently is swapping focus between my browser and IDE a couple times. I don’t know why, but this seems to prompt LiveReload to trigger again. Maybe it’s a timing problem, or something unique to IntelliJ, or just me doing something wrong :P
Go Go Gadget Mobile!
Barring that last little hiccup, combining Spring Boot DevTools with a front end build tool results in some pretty great productivity boosts. With time, maybe I’ll dilute the LiveReload issue to something a bit more measurable or reproducible, but for now, it’s not that big a tradeoff given the amount of time I save not having to manually restart my app for something as simple as CSS or JS updates.
You can checkout a sample project on GitHub that goes along with this post.
For a more in-depth look at Spring Boot DevTools, you might also be interested in Phil’s short video.