天天看點

【Spring Boot】IntelliJ IDEA實作Spring boot熱部署

【Spring Boot】IntelliJ IDEA實作Spring boot熱部署

原因:IntelliJ IDEA 預設不能自動編譯,是以隻對Spring項目引入pring-boot-devtools的依賴不能成功進行熱部署。

解決方法如下:

1. CTRL + SHIFT + A --> 查找make project automatically --> 選中 

【Spring Boot】IntelliJ IDEA實作Spring boot熱部署

2. CTRL + SHIFT + A --> 查找Registry --> 找到并勾選compiler.automake.allow.when.app.running

【Spring Boot】IntelliJ IDEA實作Spring boot熱部署

3.引入依賴

(1)加maven依賴

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-devtools</artifactId>

    <optional>true</optional><!-- optional=true,依賴不會傳遞,該項目依賴devtools;之後依賴該項目的項目如果想要使用devtools,需要重新引入 -->

</dependency>

(2)開啟熱部署

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

<configuration>

<fork>true</fork>

</configuration>

</plugin>

</plugins>

</build>

4.浏覽器禁用緩存(如Chrome/360浏覽器等)

F12(或Ctrl+Shift+J或Ctrl+Shift+I)--> NetWork --> Disable Cache(while DevTools is open)

【Spring Boot】IntelliJ IDEA實作Spring boot熱部署

5.重新啟動項目即可成功進行熱部署