我正在尝试通过 VSCode 调试 Spring bootRun 应用程序。我不确定正确的启动配置是什么。
这就是我在终端中启动程序的方式
./gradlew bootRun -Dspring.profiles.active=local
这些是我尝试过的当前配置,但没有运气。
启动.json
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug",
"args": [
"bootRun",
"-Dspring.profiles.active=local"
],
"mainClass": "com.test.Application",
"request": "launch"
},
{
"type": "java",
"preLaunchTask": "gradle",
"name": "Debug Task",
"request": "attach",
"hostName": "localhost",
"port": 5005
}
]
}
任务.json
{
"version": "2.0.0",
"tasks": [
{
"label": "gradle",
"type": "shell",
"command": "./gradlew",
"args": [
"bootRun",
"-Dspring.profiles.active=local",
"--debug-jvm"
],
"problemMatcher": []
}
]
}
“调试”配置吐出以下错误
No active profile set, falling back to default profiles: default
“调试任务”配置运行任务,但它会一直等到任务完成,而它永远不会完成。所以我无法调试它。
编辑1:
所以如果我运行这个任务
{
"version": "2.0.0",
"tasks": [
{
"label": "gradle",
"type": "shell",
"command": "./gradlew",
"args": [
"bootRun",
"-Dspring.profiles.active=local",
"--debug-jvm"
],
"problemMatcher": []
}
]
}
然后运行这个启动配置
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "task 2",
"request": "attach",
"hostName": "localhost",
"port": 5005
}
]
}
我可以调试应用程序,但这只会将调试器附加到进程。因此,当我完成调试时,我必须手动终止该进程。理想情况下,我想通过启动配置使用 vscode 启动和停止应用程序。
编辑2:
我可以通过这种配置在 IntelliJ 中实现我想要的,但我希望能够在 vscode 中做到这一点。
编辑 3:
这是我目前的配置,效果很好。我可以使用 CMD-SHFT-B 启动程序,然后按 F5 来启动调试器。
启动.json
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug",
"request": "attach",
"hostName": "localhost",
"port": 5005
}
]
}
任务.json
{
"version": "2.0.0",
"tasks": [
{
"label": "gradle",
"type": "shell",
"command": "./gradlew",
"args": [
"bootRun",
"-Dspring.profiles.active=local",
"--debug-jvm"
],
"dependsOn": [
"kill-java"
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "kill-java",
"type": "shell",
"command": "pkill",
"args": [
"java"
]
}
]
}