1.項(xiàng)目依賴添加spring-dev-tools
2.application.yml添加
spring:
devtools:
remote:
secret: thisismysecret
3.在 Intellij IDEA 當(dāng)中的 Preference -> Build, Execution, Deployment -> Compiler 中勾選 Build project automatically
4.在 IDEA 的 registry 中勾選 compiler.automake.allow.when.app.running (macOS 下使用 option + command + shift + / 涵卵,Windows 下使用 Ctrl + Alt + Shift + / 調(diào)出 registry 菜單)
然后尋找到 compiler.automake.allow.when.app.running炭玫,進(jìn)行勾選
最后重啟 IDE躏仇,在 Run/Debug Configurations 中新建一個(gè) Spring Boot 模板的配置梗搅。其中 Main Class 填入 org.springframework.boot.devtools.RemoteSpringApplication (注意哦扒磁,點(diǎn)右邊的省略號(hào)按鈕勾選 include non-project classes 的選擇才有效)糕档。然后在 Program arguments 中填入服務(wù)地址志衍,比如你的服務(wù)端口是 8080 就填 http://localhost:8080; Working Directory 填寫(xiě) 弊予,而 Use classpath of module 選擇當(dāng)前項(xiàng)目即可。