The Spring Boot Developer Tools

Getting into Spring Boot, part 6 The Spring Boot Developer Tools

Compared with the early JEE development of Spring feels a boat, such as magic. So fast, So intuitively. Just a few things to tarnish the Coding fun. You must restart the Server for every Change? And could not update the web pages automatically?

Companies

With the Spring Boot Dev Tools, some Work in the Java development go even easier by the Hand.
With the Spring Boot Dev Tools, some Work in the Java development go even easier by the Hand.

(Image: mohamed_hassan (image edited) / Pixabay )

After we have made in the first articles in the series with the basics of Spring and Spring Boot is a little familiar, it should go in this contribution, for the first time to tools. There are a whole series, and they are occasionally presented from time to time.

Probably the most important tool in the Spring Boot Developer Tools, short DevTools are. The Developer Tools are a part of Spring Boot, so the right official tool. You must be added to the project but which nevertheless explicitly agreed to this. The Installation is done by including a dependency in the POM of the project:

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

In the Spring Tool Suite (STS) can be integrated to the module directly via the context menu: right-click on pom.xml and then Spring > Add DevTools select.

In the Spring Tool Suite, you will recognize the active DevTools to the note in parentheses after the name of the project.

In the Spring Tool Suite, you will recognize the active DevTools to the note in parentheses after the name of the project.(Image: Dr. Koller)

After a reboot, the developer tools are available. In the STS-Package Explorer, attention is drawn to the enabled DevTools by the entry behind the project name.

When you Start an application, the following note in the console, also found:

Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable

In order to ensure that the DevTools are ready to function, it should be in accordance with the Embed review.

Flash Restart Faster

The main Feature of the collection, the automatic Restart is. After Changes in the Code will be triggered when a certain Trigger a restart of the Embedded Tomcat. In the case of Eclipse or STS of this Trigger is to Save a Source Code file in the class path.

Spring Boot works with two separate class loaders, so that only the Java classes and Properties of one’s own project in the Restart must Classloader to be re-loaded. Libraries in the Dependencies are managed by a different Classloader and remain loaded. The Restart happens so very quickly.

You can see the restart of the console output when Saving a file. Changes to static Assets, like images or Thymeleaf Templates under /META-INF/maven, /META-INF/resources, /resources, /static, /public or /templates not trigger a Restart. The list of folders can be customize.

Important: Newly added to the Jars in the pom.xml do not fire the Trigger also. After Adding a Dependency has to be Hand-started – a circumstance, we forget that in all of the new level of comfort easily. The Restart is the most powerful Feature of the developer tools, and justifies the use. But there are other helpers.

Ungecacht

Thymeleaf Templates are cached in the normal case of Spring Boot. Clearly, the users of the pages to get to see as quickly as possible. In the development of the is, however, not disturbing, because you can see Changes to the Template after a Browser Refresh immediately. In order to get the effect of a Change to the face, you must restart the whole application.

The DevTools to eliminate this shortcoming and disable the Cache during development. A page refresh in the Browser now displays the changed Templates immediately. Even if it feels in the development of similar, it has nothing to do with the automatic Restart to.

The Cache can be switched off by the way, even without the DevTools, the corresponding Property in application.properties means spring.thymeleaf.cache and need to disable the Cache false be set.

spring.thymeleaf.cache: false

Live Reloaded

Wouldn’t it be nice, if even that will have to Refresh could be omitted in the Browser? So the Save html file and immediately see the impact? No Problem, there’s a tool, it’s called “Live Reload”. However, the eponymous browser extension for the Feature required. To get them on the side of the provider for the major browsers (Chrome, Firefox, Safari). Depending on the Browser, there are going to note any special features.

The Icon of Live Reload is a subtle note on the Status of the extension. Here it is disabled.

The Icon of Live Reload is a subtle note on the Status of the extension. Here it is disabled.(Image: Dr. Koller)

The successful Installation, here in Chrome, you can see the Refresh icon next to the address bar. The extension can be changed by clicking on the icon – turn on or off. The small circle in the middle of the Icons must be filled out for Live Reload is active. In the console, a note on live should find after installing the DevTools also reload:

LiveReload server is running on port 35729

If you now change the Code in the Browser page that is displayed, for example, in the to add a Text or a Button in a Template or something in the CSS changes, these Changes appear as a Ghost in the Browser. The extension requires a comprehensive set of rights to read and Modify data on the visited websites. Who wouldn’t want that, may limit the feature on in the settings of the plug-in, selectable pages.

Conclusion

The Developer Tools are a powerful and useful tool, that is actually, in each of the project are indispensable. Anyone who has ever designed, the automatic Restart will not want to do without the Feature. The already fast Start-up of the application by the embedded Tomcat is still accelerating change. And the Rest of the tools is helpful, though not to the same extent. Further information on the DevTools are to be found in the Spring Boot documentation.

(ID:47074548)

Ready to see us in action:

More To Explore

IWanta.tech
Logo
Enable registration in settings - general
Have any project in mind?

Contact us:

small_c_popup.png