To automatically restart a Spring Boot project in IntelliJ IDEA and check static and template changes, you can use Spring Boot DevTools. This tool provides a convenient way to automatically restart the application when files change. Here's how you can set it up:
Add Spring Boot DevTools to your project:
Make sure spring-boot-devtools is included in your pom.xml (for Maven) or build.gradle (for Gradle).
For Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
For Gradle:
implementation 'org.springframework.boot:spring-boot-devtools'
Enable Automatic Build in IntelliJ IDEA:
File > Settings (or IntelliJ IDEA > Preferences on macOS).Build, Execution, Deployment > Compiler.Build project automatically.To enable this for ongoing changes:
Ctrl+Shift+A (or Cmd+Shift+A on macOS) to open the "Actions" popup.registry and select Registry....compiler.automake.allow.when.app.running.File > Settings > Advanced Settings and check Allow auto-make to start even if developed application is currently running
Use Spring Boot DevTools:
When you have spring-boot-devtools in your classpath, your application will automatically restart whenever files on the classpath change. This includes changes in .java, .properties, and .yml files.
Optional: Configure DevTools for Static Resources:
By default, Spring Boot DevTools will detect changes to static files (e.g., HTML, CSS, JavaScript) and automatically refresh the browser. If it’s not working as expected, you may need to adjust your settings:
src/main/resources/static or src/main/resources/templates./META-INF/maven and /resources directories. If your resources are elsewhere, you may need to adjust the spring.devtools.restart.additional-paths property.Running the Application:
Ctrl+Shift+R or Cmd+Shift+R).By following these steps, your Spring Boot application will automatically restart in IntelliJ IDEA when you make changes to static files and templates, allowing you to see your changes immediately.