首先参考idea 官方介绍的文章:
-
Debug a Java application using a Dockerfile
https://www.jetbrains.com/help/idea/debug-a-java-application-using-a-dockerfile.html
-
Run and debug a Spring Boot application using Docker Compose
https://www.jetbrains.com/help/idea/debugging-your-first-java-application.html?_ga=2.268527929.994608184.1606746576-1928223835.1606746576
按照官方文档操作一通.我的应用是jhipster生成的springboot应用.
dockercompose 配置如下,
其中_JAVA_OPTIONS中的参数-agentlib 是按照教程从下图中拷贝而来,然而这就是坑爹的地方了
按照教程,用debug启动系统,然而debug并没有连接上, 而是出现如下错误:
Error running ‘localdockerdebug’: Unable to open debugger port (localhost:5750): java.io.IOException “handshake failed – connection prematurally closed”
还有
Error running ‘localhost:5750’: Unable to open debugger port (127.0.0.1:5750): java.net.ConnectException “Connection refused: connect”
解决方案:将docker compose文件中address 修改
- _JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5750 -Xmx256m -Xms128m
变成如下:
- _JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5750 -Xmx256m -Xms128m
*:5750 表示接受任何client端的请求,包括idea.
好了,通过debug启动, 发现系统能触发断点了,搞定!