Three, springboot hot deployment

1. spring-boot-devtools for hot deployment

The most important feature of spring-boot-devtools is hot deployment. It listens for file changes on the classpath and restarts the application immediately.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

  optional=true means that dependencies will not be passed, in other words, other projects that depend on this project need to re-introduce if they want to use devtools

  If we want to restart Spring Boot when the files in the specified folder change, we only need to configure the information in src/main/resources/application.properties.

spring.devtools.restart.additional-paths= # Additional paths to watch for changes.

Custom configuration hot deployment

  The following configuration is used for custom configuration hot deployment and can be left unset.

# Hot deployment switch, false means hot deployment is not enabled
spring.devtools.restart.enabled: true

# Specify the directory for hot deployment
#spring.devtools.restart.additional-paths: src/main/java

# The specified directory is not updated
spring.devtools.restart.exclude: test/**

If it is Intellij Idea, you need to change the following two places:

1. Tick the automatic compilation or manually recompile

File > Settings > Compiler-Build Project automatically

2. Registration

ctrl + shift + alt + / > Registry > 勾选Compiler autoMake allow when app running

Precautions

1. The devtools in the production environment will be disabled, such as the java -jar method or the custom class loader, etc., will be recognized as the production environment.

2. Packaged applications will not include devtools by default unless you disable the SpringBoot Maven plugin excludeDevtoolsproperties .

3. Thymeleaf does not need to be configured , devtools will automatically set it by default, refer to the complete properties.spring.thymeleaf.cache:false

https://github.com/spring-projects/spring-boot/blob/v1.5.7.RELEASE/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java

4. The devtools will occupy the java process in the windows resource manager. It cannot be killed in the development tool. It can only be killed manually. Otherwise, the restart will select the port to bind repeatedly and report an error.

2. Spring Loaded implements hot deployment

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
            <version>1.2.6.RELEASE</version>
        </dependency>
    </dependencies>
</plugin>

Start the project with mvn spring-boot:run .

3. Template file hot deployment

In Spring Boot, the page of the template engine is cached by default. If the page content is modified, the modified page content cannot be obtained by refreshing the page. Therefore, if we do not need the cache of the template engine, we can close it.

spring.freemarker.cache=false
spring.thymeleaf.cache=false
spring.velocity.cache=false

Official documentation: https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325014155&siteId=291194637