工欲善其事,必先利其器 ----《論語·衛靈公》
第一步 配置idea
1.ctrl+alt+s--->compiler---->make project automatically
image.png
2.ctrl+shift+alt+/ 選擇Registry,勾上 Compiler autoMake allow when app running
image.png
image.png
第二步 添加springloaded依賴
加入到spring-boot-maven-plugin這個plugin中
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
<configuration>
<fork>true</fork>
<mainClass>cn.watchbank.cooperation.WatchbankCooperationServer</mainClass>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
第三步 啟動
需要用mvn spring-boot:run啟動工程
image.png
image.png
第三步 驗證
直接修改java代碼,直接生效,對開發者毫無感知,怎一爽知了得。
補充說明
問題一 控制臺中文亂碼
用mvn spring-boot:run 啟動后可能會導致console中日志出現亂碼,解決辦法是增加啟動參數
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
image.png
問題二 用mvn spring-boot:run命令起動后沒能進入debug模式
這個問題花了不少時間解決
- 添加jvm啟動參數
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
image.png
這時啟動會提示:Listening for transport dt_socket at address: 5005
遇到這個情況先不要停掉,做完如下操作即可繼續運行。
image.png
需要按以下方法處理
image.png
image.png
image.png
最后點debug,即可繼續運行下去
image.png