SpringBoot project realizes hot deployment in IntelliJ IDEA

spring-boot-devtools is a module for developers, the most important function of which is to automatically apply code changes to the latest App.
The principle is to restart the application after discovering that the code has changed, but it is faster than manually stopping and restarting.
The deep principle is to use two ClassLoaders, one ClassLoader loads the classes that will not change (third-party Jar packages), and the other ClassLoader loads the classes that will change, called restart ClassLoader
, so that when there are code changes, the original The restart ClassLoader is discarded, and a restart ClassLoader is recreated. Since there are fewer classes to be loaded, a faster restart time is achieved.

That is, devtools will monitor file changes under the classpath, and will immediately restart the application (occurs at save time)

1. Turn on the automatic make function of idea 

1. CTRL + SHIFT + A --> find make project automatically --> select 

2. CTRL + SHIFT + A --> Find Registry --> Find and check compiler.automake.allow.when.app.running 

Finally restart the idea 

2. Use spring-boot-1.3 to start some hot deployment functions 
1. Add maven dependencies

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

2. Enable hot deployment

copy code
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
            <fork>true</fork>//该配置必须</configuration></plugin></plugins></build>    
            
        
    
copy code

3. Chrome disable cache 
F12 (or Ctrl+Shift+J or Ctrl+Shift+I) --> NetWork --> Disable Cache(while DevTools is open) 

At this point, you can happily modify the code in the idea, and you can see the effect in time after modification, without manually restarting and clearing the browser cache.

Test method:
1. Modify the class --> save: the application will restart
2. Modify the configuration file --> save: the application will restart
3. Modify the page --> save: the application will restart and the page will be refreshed (the principle is to change the spring. thymeleaf.cache is set to false)

Can not use analysis:
1. Whether the corresponding spring-boot version is correct, I am using the 1.5.3.RELEASE version here;
2. Whether the plugin has been added, and the attribute <fork>true</fork>
3. Whether Intellij IDEA is enabled Make Project Automatically.
4. If you set SpringApplication.setRegisterShutdownHook(false), the automatic restart will not work.

refer to:

http://412887952-qq-com.iteye.com/blog/2300313

Guess you like

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