How To Be More Effective In Spring

12. November 2019

I wasn't thinking about being more effective at university. I was more busy to handle new technologies than speeding up compiling or deploying my app. My first job changed my thinking about this topic, it was a big and old project and my changes took effect in approximately 10 minutes. It was depressing because I hate switching a context. In the end, I reduced that time, but still, it took about 3-5 minutes.

When I started to work in CloseIT, I was eager to understand how the app works. Usually, I try it by trial and fail. On the other hand, each build takes time and it disturbs my workflow. I was wondering if there is a way to make it faster. It was my first work experience with Spring framework, but it didn't take a long time to find people with the same problem, and that's how I found the devtools from Spring.

So, how to use the devtools in your application? It's pretty straightforward as finding it.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

Note: The <optional>true</optional> prevents SpringDevtools from being transitively applied to other modules that use your project.

Since now, the devtools are almost ready to use. The last thing is setting the automatic update of the classpath, this informs devtools that something was changed and triggers the restart. This step depends on your IDE, I use IntelliJ and my current setting looks like this picture.
Debug configuration in IntelliJ

That's all from me for now. The devtools offers more features as remote support, for example, but I didn't try this on our servers yet. The reason is that I find out a problem, we use drool rules and they don't work together with devtools. For more information see this page.

Another cool feature that I haven't tried yet is a live reload which is used by frontend guys. Simply, it automatically refreshes a browser when a resource is changed. So, you can see how your page looks as you type.

Now, I run out of my notes about testing the devtools. I hope my notes saved you some time, I didn't write a detailed how-to, because you can find more specific information on the official documentation.

Author: Jakub Horák