相信大家在用springboot開發web應用時都遇到過改動頁面上一個地方就需要重啓下服務的困惑,現在推薦給大家一種熱部署方法,可以改動頁面內容時無需重啓服務,提高開發效率;親測好使在idea
1.pom.xml文件需要調整添加依賴
注:熱部署功能spring-boot-1.3開始有的
<!--添加依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- optional=true,依賴不會傳遞,該項目依賴devtools;之後依賴myboot項目的項目如果想要使用devtools,需要重新引入 -->
<optional>true</optional>
</dependency>
2.更改idea配置
“File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,選中打勾 “Build project automatically” 。組合鍵:“Shift+Ctrl+Alt+/” ,選擇 “Registry” ,選中打勾 “compiler.automake.allow.when.app.running” 。
- 注意如果是eclipe需要在pom文件額外增加東西如下
- 注:project 中添加 spring-boot-maven-plugin,主要在eclipse中使用,idea中不需要添加此配置。
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build>