Springboot project configuration hot deployment

1. Introduce dependencies in the project and add the following configuration to the pom

<!--devtools hot deployment dependency--> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-devtools</artifactId> 
    <!--optional indicates whether the dependency is passed down true Indicates no downward transmission, the default value is false downward transmission --> 
    <optional>true</optional> 
</dependency>

 Note:


1. Devtools can implement hot deployment of pages (that is, it will take effect immediately after page modification, which can be realized by configuring spring.thymeleaf.cache=false directly in the application.properties file), and
hot deployment of class files (the class files will not be modified after modification) effective immediately) to realize hot deployment of property files.
That is, devtools will monitor the file changes under the classpath and restart the application immediately (occurring at the time of saving). Note: because of the virtual machine mechanism it uses, this restart is very fast


2. After configuring true, hot start is supported after modifying the java file, but this method belongs to project restart (faster project restart), and the value in the session will be cleared, that is, if a user logs in, You need to log in again after restarting the project. 

 By default, file modifications in /META-INF/maven, /META-INF/resources, /resources, /static, /templates, /public folders will not cause the application to restart, but will reload (devtools embedded A LiveReload server is installed, when the resource changes, the browser refreshes).

configuration of devtools

Configure devtools in application.yml

spring:
  devtools:
    restart:
      enabled: true  #设置开启热部署
      additional-paths: src/main/java #重启目录
      exclude: WEB-INF/**
  freemarker:
    cache: false    #页面不加载缓存,修改即时生效

2. Turn on the automatic compilation function of idea, File --> Settings --> Compiler --> Build Project automatically

      box selected.

3. Idea opens the project to run the automatic make function, press the shortcut key Ctrl+Shift+Alt+/   , then select registry , and check compiler.automake.allow.when.app.running 

(Note: The order may be different, look down)


 4. After restarting IDEA, run the project, modify the code, and wait a few seconds. The following restartedMain appears on the console, indicating that the configuration is successful.

Guess you like

Origin blog.csdn.net/weixin_43824829/article/details/127808616