我使用micronaut和Visual Studio代码创建了一个微服务。当我使用gradlew.bat运行服务时,一切正常。我想使用Visual Studio代码调试微服务,但注释处理无法正常工作。
当我在Visual Studio代码中调试服务时,它将运行主类并开始侦听localhost端口,但是找不到我的控制器 这是我的启动配置:
{
"type": "java",
"name": "Debug (Launch)-Application<keycloak>",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "com.test.Application",
"args": "",
"projectName": "keycloak"
}
这是我的gradle文件:
buildscript {
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:2.0.4"
classpath "io.spring.gradle:dependency-management-plugin:1.0.5.RELEASE"
classpath "net.ltgt.gradle:gradle-apt-plugin:0.15"
}
}
version "0.1"
group "com.test"
apply plugin:"io.spring.dependency-management"
apply plugin:"com.github.johnrengelman.shadow"
apply plugin:"application"
apply plugin:"java"
apply plugin:"net.ltgt.apt-eclipse"
apply plugin:"net.ltgt.apt-idea"
repositories {
mavenLocal()
mavenCentral()
maven { url "https://jcenter.bintray.com" }
}
dependencyManagement {
imports {
mavenBom 'io.micronaut:bom:1.0.0.M4'
}
}
dependencies {
annotationProcessor "io.micronaut:inject-java"
compile "io.micronaut:inject"
compile "io.micronaut:runtime"
compile "io.micronaut:http-client"
compile "io.micronaut:http-server-netty"
compile "be.looorent:keycloak-micronaut-adapter:1.3.0"
compileOnly "io.micronaut:inject-java"
runtime "ch.qos.logback:logback-classic:1.2.3"
testCompile "junit:junit:4.12"
testCompile "io.micronaut:inject-java"
}
shadowJar {
mergeServiceFiles()
}
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1')
mainClassName = "com.test.Application"
compileJava.options.compilerArgs += '-parameters'
compileTestJava.options.compilerArgs += '-parameters'
预先感谢
答案 0 :(得分:2)
我不知道如何直接在VSC中调试应用程序,但是可以肯定的是,您可以从命令行运行服务,然后使用远程调试附加过程。
为此,请执行以下步骤:
更改gradle文件并使用Java远程调试
更改此行:
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1')
至:
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1','-Xdebug',"-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n")
(请注意jvm参数中的端口8000
)
添加此启动配置
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 8000 -> here use the same port you use in the jvm arg
}
使用命令
8000