In the actual development of Spring Boot hot deployment, modifying a page data or logical function requires a restart of the app. This virtually reduces the development efficiency, so it is necessary to use thermal deployment. What is a hot deployment? After the application starts, it will load the compiled class file into the virtual machine, under normal circumstances when the project modifies the source file, it needs to be completely recompiled and reloaded (need to restart the app). The hot deployment is to listen to changes in the class file, only the modified class reload, without the need to restart the application, making development easier. Spring Boot configuration enables hot deployment The first way: the Maven plugin-springloaded adds springloaded dependencies in the Spring-boot-maven-plugin plug-in configuration.
<Build><Plugins><Plugin><Groupid>org.springframework.boot</Groupid><Artifactid>spring-boot-maven-plugin</Artifactid><Dependencies><dependency> < groupid>org.springframework</ groupid> <artifactid>springloaded </artifactid> < version>1.2.5.release</version > </dependency> </dependencies> </plugin> </plugins></ BUILD>
by command: MVN Spring-boot:run launches the app, modifies the controller's code or modifies the HTML page (remember to pressctrl+shirt+f9Reload the modified class file, and then refresh the page, you will find that the display results change. Note: The first way to launch the app is valid for MVN spring-boot:run this way, but not for running the Application.java startup app directly.
Note 1: If you find that there is no hot deployment effect, you need to check if automatic compilation is turned on in the idea configuration:
Open Preferences > Compiler, tick Build project automatically
NOTE 2: If you use the Thymeleaf template engine, you need to set the template default cache to False
Add in Application.properties:
#禁止thymeleaf缓存(建议:开发环境设置为false,生成环境设置为true)spring.thymeleaf.cache=false
The second way: rely on the Spring-boot-devtools Thermal deployment module Pom.xml Add dependencies:
<!-- 热部署模块 --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <!-- 这个需要为 true 热部署才有效 --></dependency>
Restart the app, modify the controller's code or modify the HTML page and then refresh the page, and you will find that the display results change.
Spring Boot Hot Deployment