Spring Boot hotswap with IntelliJ IDE
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Spring Boot is a popular framework in the Java ecosystem that simplifies the process of creating stand-alone, production-grade Spring-based applications. While developing Spring Boot applications, developers often encounter the need to see changes reflected in their applications without having to restart the server. This is where "hotswap" or "hot reloading" comes into play. In this article, we'll explore how to achieve hotswap with Spring Boot using IntelliJ IDEA.
What is Hotswap?
Hotswap refers to the ability to replace or update the code inside a running Java Virtual Machine (JVM) without needing to stop, recompile, and restart the application. This capability can drastically speed up the development process, especially when you're making small changes and want immediate feedback.
Enabling Hotswap in IntelliJ IDEA
IntelliJ IDEA is one of the most popular IDEs for Java development and provides built-in support for hotswapping code in JVM applications. Here's how to set it up for a Spring Boot project:
Prerequisites
- IntelliJ IDEA: Ensure you have the latest version of IntelliJ IDEA installed.
- Spring Boot Project: A basic Spring Boot project set up with Maven or Gradle.
- JRebel Plugin (optional): For more advanced hotswap capabilities, you can use JRebel, a commercial tool that extends basic hotswap functionality.
Basic Hotswap Setup with IntelliJ IDEA
- Enable Automatic Build: IntelliJ offers an "Automatic Build" feature that triggers a build whenever you save a file.
- Go to
File > Settings > Build, Execution, Deployment > Compilerand check "Build project automatically". - To enable this feature even outside the debug session, use
Ctrl + Shift + Aand type "Registry". Search forcompiler.automake.allow.when.app.runningand enable it.
- Run in Debug Mode: Start your Spring Boot application in Debug mode. This enables the hotswap functionality in IntelliJ. Use the "Debug" button instead of the "Run" button.
- Apply Changes: After making changes to your code, use
Ctrl + F9or selectBuild > Make Projectto compile changes. IntelliJ will attempt to hotswap the modified classes.
Advanced Hotswap with JRebel
JRebel is a tool that provides enhanced hotswap capabilities compared to the JVM's default, allowing for more extensive changes to be noticed without restarts, such as changes to method signatures and class structures.
- Install JRebel:
- Install the JRebel plugin from the IntelliJ IDEA Plugin repository.
- You may need to purchase a license or use a free trial.
- Configure JRebel:
- Once installed, enable JRebel in your project by right-clicking your project in the Project Explorer and selecting
JRebel > Enable JRebel. - Run your Spring Boot application using the
JRebelrun configuration created by the plugin.
- Apply code changes: Code changes are automatically picked up by JRebel once you save the file, without requiring any manual building.
Managing Dependencies with Development Tools
Spring Boot does provide tools for hotswapping changes automatically with external libraries:
- Spring Loaded: An older solution, designed to work in conjunction with Spring Boot DevTools, but it has seen limited updates.
- Spring Boot DevTools: Automatically restarts your application whenever files on the classpath change.
Spring Boot DevTools Setup
- Add Dependency: Add Spring Boot DevTools to your Maven or Gradle project:Maven:
Gradle:
- Run Application: Just run your Spring Boot application in the usual way. DevTools will handle restarting the application intelligently.
Key Points Summary
Here's a quick reference table summarizing the key points regarding Spring Boot hotswap options with IntelliJ:
| Feature | IntelliJ Built-in | JRebel | Spring Boot DevTools |
| Basic Changes | Yes (limited) | Yes (extensive) | Yes (restarts application) |
| Setup Required | Minimal | Plugin installation | Dependency addition |
| Debugging Support | Required | Optional | Optional (more restarts) |
| Cost | Free | Commercial (with trials) | Free |
Conclusion
Hotswapping is an invaluable tool when developing applications, as it significantly enhances productivity by reducing downtime from restarts. While IntelliJ offers basic hotswap capabilities, tools like JRebel and Spring Boot DevTools provide more flexibility and ease of use. Depending on your project needs and budget, you can choose the best approach to streamline your development workflow.
Related reading
- Spring Boot How do you specify an environment variable that has dashes in the application.properties?
- Spring Boot How to add another WAR files to the embedded tomcat?
- Spring Boot How to disable startup log message Starting Application on mbp with PID 99446
- Spring Boot how to hide passwords in properties file
- Spring boot How to read resource from classpath in unit test
- Spring Boot How to specify the PasswordEncoder?
- Spring Boot how to use multiple yml files
- Spring boot http response compression doesn't work for some User-Agents

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.