INTRODUCTION

We are learning what is  hot swapping in spring and how hot swapping help developer to save time. Also what are the features and how to disable the hot swap. It is mainly spring boot feature where developer don't need to start the server while development.


What is hot swapping ?

Spring Boot has a useful feature that enables the application to automatically restart when you change your Java code. This feature can be particularly useful when you are in development phase and you don’t want to manually restart your instance. This automatic restart of your application is called Hot Swap.


How we can use hot swapping ? 

To enable hot swap or auto restart of your spring boot application we need to add below dependency in your pom.xml file. When spring boot find devTool present , it enables automatic feature.


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


What are main features ?

1) Live reload static resources :

The static resources will be automatically updated without the need to restart the application. This is very useful if you are developing a frontend application and your web files are changing. So spring will simply reload them without recompile and redeploy the application.

2) Spring restart using trigger file : 

Spring will create 2 class loaders, 1 with external libraries and 1 with project class. We can provide this trigger file using spring.devtools.restart.trigger-file option. We can provide this property as a global property of the spring devTools or we can application.properties file.

3) Global Setting : 

spring-boot-devTools provides a way to configure global settings that are not added with any application. This file is named as .spring-boot-devtools.properties and it located at $HOME. This configuration you can apply in your machine.

4) Remote update :

Spring Boot development tool also support update and restart for remote application. The remote client will monitor changes in the local classpath and will trigger a restart after pushing these changes to the remote server. 

5) Exclude files : 

spring-boot-devtools will not restart if you change resources at /META-INF/ resources, /resources, /static, /template, if you want you can change this behavior using spring.devtools.restart.exclude property.

Disable the hot swap : 

If start is done for small change so its very slow down your machine or disturb the development so you can disable the hot swap in application.properties file with property spring.devtools.restart.enabled.






Advantages of hot swap : 

1) Reduce development time.
2) Auto deploy application

Disadvantages of hot swap : 

1) application performance become slow.


CONCLUSION : 

We have learned how devTool helps to reduce development time by automatic restarting your application.


USEFUL Links : 






About me

I am Suraj Ladda. I am working as Software Developer in IT industry.

Contact me

surajladda07@gmail.com