how to make auto reload with Spring-boot on IDEA Intellij
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Developing Spring Boot applications with automatic reloading capabilities can significantly improve developer productivity and the feedback loop. Auto reload allows you to see the effects of code changes without manually restarting the application. In this article, we'll explore how to set up auto reload in a Spring Boot project using IntelliJ IDEA, leveraging tools like Spring DevTools and LiveReload.
Prerequisites
Before we proceed, ensure you have the following tools installed:
- IntelliJ IDEA (Community or Ultimate)
- Java Development Kit (JDK) 8 or higher
- Apache Maven or Gradle
- Basic understanding of Spring Boot
Step-by-Step Guide
Step 1: Set Up a Spring Boot Project
- Create a New Project: Open IntelliJ IDEA and create a new Spring Boot project. You can either start from scratch or import an existing project.
- Add Spring Initializr:
Utilize Spring Initializr within IntelliJ IDEA or from start.spring.io to bootstrap your project. Ensure to include dependencies likeSpring DevTools.
Step 2: Add Spring Boot DevTools
Spring Boot DevTools supports automatic restarts and speeding up the development cycle.
- Modify
pom.xmlorbuild.gradle:For Maven, add the following dependency in yourpom.xml:
For Gradle, add the following line in build.gradle:
- Reimport the Project: After updating the build file, re-import the project in IntelliJ IDEA to ensure all dependencies are correctly downloaded.
Step 3: Enable Automatic Restart
Sprint Boot DevTools enhances the development experience by enabling automatic restarts.
- Configure Automatic Restart: By default, after adding Spring Boot DevTools, every code change triggers an automatic restart. You don't need to do additional configuration.
- Exclude Resources: If certain files should not trigger a restart, exclude them by modifying
src/main/resources/META-INF/spring-devtools.properties:
Step 4: LiveReload for Browser Refresh
LiveReload automatically refreshes the browser whenever a resource is updated.
- Configure LiveReload: LiveReload is included in Spring Boot DevTools. To use it, download a browser extension compatible with LiveReload or configure your IDE plugin.
- Build for LiveReload:
- Ensure your application is running and you've configured the browser or IDE to support LiveReload.
- Upon changes, Spring Boot DevTools will trigger a context restart, and LiveReload will refresh your browser.
Step 5: IntelliJ IDEA Configuration
- Enable Build Project Automatically:
- Go to
File > Settings(orIntelliJ IDEA > Preferenceson macOS). - Navigate to
Build, Execution, Deployment > Compiler. - Check the
Build project automaticallyoption.
- Make on Save:
- Help the IDE in automatically building the project when files are saved.
- Navigate to
Preferences > Advanced Settings. - Under
Compiler, enableAuto-make if the project is dirtyoption.
Conclusion
Setting up auto reload in Spring Boot projects using IntelliJ IDEA can greatly improve workflow efficiency by reducing manual restarts. By leveraging Spring Boot DevTools and LiveReload, developers can keep a tight feedback loop, see their changes in real-time, and focus more on writing code.
Key Points Summary
| Feature | Tool/Configuration | Description |
| Spring Boot Project Setup | Spring Initializr | Bootstrap project with required dependencies |
| DevTools Setup | pom.xml/build.gradle | Adds capabilities for automatic restarts |
| Automatic Restart | Spring Boot DevTools | Default feature; No additional setup needed |
| Excluding Resources | spring-devtools.properties | Define resources to avoid trigger on changes |
| Browser Auto-Refresh | LiveReload | Automatically refreshes the browser upon changes |
| IntelliJ Configuration | Build Project Automatically and Make on Save | Optimize the auto-build process |
With this setup in place, you can enjoy a smoother development experience, focusing more on application logic and less on managing your development environment.
Related reading
- How to make my Java Swing application a Client-Server application?
- How to make reactive webclient follow 3XX-redirects?
- How to make Spring Cloud Stream consumer in Webflux application?
- How to make Spring server to start even if database is down?
- how to make StdIn.isEmpty return true?
- How to manage exceptions thrown in filters in Spring?
- How to manually include external aar package using Gradle for Android
- How to manually trigger Spring validation?

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.