spring boot hot start

There are two ways to hot start spring boot

1. It is loaded in the form of a Maven plug-in, so use the Maven command mvn spring-boot:run to start at startup, and the application.run method will be invalid, because the Maven plug-in mechanism has been bypassed when starting through the application. .

<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> 

2. Spring-boot-devtools
No matter how you start the application, you can restart the application after modifying the file.

(1) If you find that there is no hot deployment effect, you need to check whether automatic compilation is turned on in the IDE configuration.

(2) If you use the Thymeleaf template engine, you need to set the template default cache to false

#Disable thymeleaf caching (recommended: the development environment is set to false, the production environment is set to true)
spring.thymeleaf.cache=false

(3) For devtools, you can specify a directory or exclude a directory for hot deployment

#Adding files in that directory requires restart
spring.devtools.restart.additional-paths=src/main/java
#Exclude files in that directory without restart
spring.devtools.restart.exclude=static/**,public/**

(4) By default, file modifications in /META-INF/maven, /META-INF/resources, /resources, /static, /templates, /public folders will not restart the application, but will reload (devtools embeds a LiveReload Server, when the resource changes, the browser refreshes)

(5) Configure spring.devtools.restart.enabled=false in application.properties. At this time, the restart class loader will also be initialized, but will not monitor file updates. Call System.setProperty("spring.devtools.restart.enabled", "false"); before SprintApplication.run; to turn off restart support completely.

Guess you like

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