Every developer out there wants to be as productive as possible. However, sometimes there are things that stand in our way.
Imagine a normal Spring Boot web application. Each time we make a change to a template view or to a Java class, we need to restart our application in order to preview the changes in our browser.
The time it takes the container to reload varies. In make case, it is around 17 seconds. If we do this rarely, no problem. But, if we are in the development phase, we are constantly changing Thymeleaf views (could be Velocity, Mustache or any other framework). We are also constantly changing some of our Java code. And each time we want to preview our work, we are forced to restart our app. Needless to say how annoying this can become over time…
Fortunately for us, with the creation of Spring Boot Dev Tools, things don’t have to be this way:) This module was introduced with Spring 1.3 and aims to increase the productivity of developers. The main features of Spring Boot Dev Tools are:
- No need to restart the container when you make changes to views. Any modification you make to a view can be seen directly in the browser, by pressing the refresh button. Thymeleaf, Freemarker, Groovy Templates, Velocity and Mustache are all supported.
- Automatic restart of the Spring container each time you modify a Java class. Any classpath file changes will automatically trigger an application restart that is faster than a cold restart. In my case, it takes half the time.
- Live reload integration. Manually clicking the browser refresh button each time something changes might become a little tedious. Spring Boot Dev Tools includes an embedded LiveReload server. LiveReload is a simple protocol that allows your IDE to automatically trigger a browser refresh whenever a change is detected.
So, with Spring Boot Dev Tools, you never have to lose time and restart your application after each change. I think this is pretty cool:)
Making Spring Boot Dev Tools work with IntelliJ
Normally, configuring an application to use Spring Boot Dev Tools is easy. You just need to add a dependency in the pom.xml file.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>
But, if you are using IntelliJ, then it is not enough. There are two more things that you need to configure to make this tool work with IntelliJ.
a) You need to enable the “Make project automatically” option. You can find it in Settings – Build, Execution, Deployment – Compilerb) You also need to modify an IntelliJ registry key. To open the registry, just press SHIFT+CTRL+A. In the pop-up window, type registry and go to this option. In the registry window, enable the “compiler.automake.allow.when.app.running” check-box.That’s it. Now Spring Boot Dev Tools will work with IntelliJ. I have also created a YouTube tutorial that shows you how to make all the configurations step by step. You can find it at https://www.youtube.com/watch?v=VWF7vCJSqrA&feature=youtu.be