工欲善其事,必先利其器 ----《论语·卫灵公》
第一步 配置idea
1.ctrl+alt+s--->compiler---->make project automatically
![](https://img.haomeiwen.com/i1514751/0dedd4218b3d7a0f.png)
2.ctrl+shift+alt+/ 选择Registry,勾上 Compiler autoMake allow when app running
![](https://img.haomeiwen.com/i1514751/92645075420d7f7e.png)
![](https://img.haomeiwen.com/i1514751/5e2fbdc6bd50d9be.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启动工程
![](https://img.haomeiwen.com/i1514751/5be2541d4e2b503f.png)
![](https://img.haomeiwen.com/i1514751/8a65ecdf827d0b12.png)
第三步 验证
直接修改java代码,直接生效,对开发者毫无感知,怎一爽知了得。
补充说明
问题一 控制台中文乱码
用mvn spring-boot:run 启动后可能会导致console中日志出现乱码,解决办法是增加启动参数
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
![](https://img.haomeiwen.com/i1514751/1b5ca19426938625.png)
问题二 用mvn spring-boot:run命令起动后没能进入debug模式
这个问题花了不少时间解决
- 添加jvm启动参数
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
![](https://img.haomeiwen.com/i1514751/b326959e0378d55e.png)
这时启动会提示:Listening for transport dt_socket at address: 5005
遇到这个情况先不要停掉,做完如下操作即可继续运行。
![](https://img.haomeiwen.com/i1514751/1b7c7f27809e4a7e.png)
需要按以下方法处理
![](https://img.haomeiwen.com/i1514751/57f2224e46191664.png)
![](https://img.haomeiwen.com/i1514751/4801d1f94213512f.png)
![](https://img.haomeiwen.com/i1514751/09f506d208c2c4c1.png)
最后点debug,即可继续运行下去
![](https://img.haomeiwen.com/i1514751/582ef5b0f77f52a6.png)
网友评论