SpringBoot學習之路:12.Spring Boot使用idea開發如何配置熱加載

          java開發的ide用最多的無非就是eclipse和idea,在eclipse中開發springboot,要使項目熱加載資源只須要在pom文件中引入springboot的開發工devtools便可。可是該工具在使用idea開發springboot時單純的引入並不起做用,還須要一些代碼支持和idea設置才能生效。下面咱們就在idea中使用maven構建的springboot項目進行熱部署配置。java

1.使用maven構建一個springboot項目

2.引入springboot開發工具包

打開項目中的pom.xml文件,加入如下依賴:spring

<!--開發工具依賴-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
</dependency>

注意:也能夠在構建的時候勾選上devtools工具包springboot

3.配置參數是devtools生效

單純的引入上面的devtools工具包是不起做用的,咱們還須要在maven編譯插件處配置一個參數:app

<build>
    <!--編譯插件配置-->
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <!--沒有該項配置,devtools不會起做用-->
                <fork>true</fork></configuration>
        </plugin>
    </plugins>
</build>

4.設置idea的自動編譯項目

打開idea的設置,找到編譯,勾選自動編譯項(File—>Settings—>Bulid—>Compiler )eclipse

5.在idea中註冊maven自動編譯項

首先使用快捷鍵ctrl + Shift + Alt + / 打開Maintenance插件註冊界面maven

而後點擊註冊進入idea的插件註冊界面ide

最後找到compiler.automake.allow.when.app.running這一項勾選,使maven的自動編譯插件註冊到idea中。spring-boot

親測有效!工具

個人idea版本:開發工具

相關文章
相關標籤/搜索