Hi!
I am having issues with seeing live application hovers in the Spring Boot Tools extension.
My environment:
Ubuntu 18.04
Visual Studio Code
JAVA_HOME: /usr/lib/jvm/java-11-openjdk-amd64
App: https://github.com/spring-projects/spring-petclinic
I've installed the Spring Boot Tools, latest version as of now.
I checked the vscode-spring-boot-debug-log and it doesn't look good:
Activating 'vscode-spring-boot' extension
Found java exe: /usr/lib/jvm/java-11-openjdk-amd64/bin/java
isJavaEightOrHigher => true
Redirecting server logs to /dev/null
ERR: Disabling server log output. No more output will be sent after this.
ERR:
Child process connected on port 45556
When I hover over a section in java file, I see an error in the Log(Window):
[2019-12-13 15:22:48.931] [renderer1] [error] The request (id: 55, method: 'textDocument/hover') has been cancelled: Error: The request (id: 55, method: 'textDocument/hover') has been cancelled
at /home/ivo/.vscode/extensions/redhat.java-0.54.2/dist/extension.js:1:72946
at /home/ivo/.vscode/extensions/redhat.java-0.54.2/dist/extension.js:1:73240
at Immediate.
at processImmediate (internal/timers.js:439:21)
I've attached both logs
The info in the logs is not very interesting. The one in 'WINDOW' appears to be from the Redhat Java extensions so has not much relation to problems in the spring boot language server.
The `vscode-spring-boot-debug-log' basically just has an information message saying that logging has been disabled.
To get more interesting log output you can enable the log output via a preference. For example something like his in settings.json:
{
"spring-boot.ls.logfile": "/tmp/boot-ls-log.txt"
}
I think I know why you are not getting the live hover information though. A few things have changed both in spring boot and in the tooling.
Firstly, in spring boot, the jmx support is no longer enabled by default in recent versions (which the Petclinic app uses). So something/someone has to enable it explicitly when you launch the app. This happens automatically for apps launched from the Eclipse Boot Dashboard. For any other kind of launch you have to do it yourself. For example when I launch the PetClinic app from the commandline I do it like this:
java -Dspring.jmx.enabled=true -Dspring.application.admin.enabled=true -jar target/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar
How did you launch the petclinic app? Did you enable JMX in spring?
Secondly, in the spring-boot tooling, the language server no longer auto connects to most processes (apps launched from Eclipse Boot Dashboard are an exception). You have to do that explicitly. In vscode you do this as follows:
Perhaps with this additional information you are able to get it working?
If not, we can try trouble shoot more. In that case:
@evowilliamson If you have a chance to try... could you let us know if after enabling JMX for petclinic and using the 'Manage Live Boot Process Connections' command in vscode to connect to the process... things work as expected?
In the mean time I'll assume that is the case and close this ticket. But we can of course re-open it and take another look if you are still experiencing problems.
@kdvolder I will try today. I'll have some time after the break!
@kdvolder,
When I mvn install the app and start the app from a terminal in the workspace, activating jmx in spring boot, and after selecting the live spring boot process, all is OK.
But when I start the process by right-clicking the spring-petclinic option in the SPRING-BOOT-DASHBOARD, things go wrong at the moment of selecting the live spring boot process.
I've included the boot-ls-log.txt file that contains the errors. I've also included my launch.json file that I use to spin off the debug process.
debug.zip
Is there anything wrong with how I am providing the -D args to the process ? I've also tried splitting up the string in different elements in the list, but I got the same result: "args": [
"-Dspring.jmx.enabled=true", "-Dspring.application.admin.enabled=true"
]
Thanks in advance!
I think the -D arguments are not arguments to your app but arguments to the JVM itself so you have to put them as 'vmArgs' not 'args'.
I.e. if you look at how it is launched on the CLI:
java ..vmArgs... -jar target/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar ..args...
You will see that the -D arguments where placed right afther the java executable and before the -jar. This is where the so called 'vmArgs' are.
Also... yes I think in the launch.json file you put the arguments split up individually into a json list rather than as just one long string.
@kdvolder
Splitting up both arguments in array values, resulted in an error:
{
"type": "java",
"name": "Debug (Launch)-PetClinicApplication<spring-petclinic>",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "org.springframework.samples.petclinic.PetClinicApplication",
"projectName": "spring-petclinic",
"vmArgs": [
"-Dspring.jmx.enabled=true", "-Dspring.application.admin.enabled=true"
]
}
Caused by: java.lang.IllegalArgumentException: Invalid boolean value 'true,-Dspring.application.admin.enabled=true'
Moving both arguments in the same string, results in no errors, but doesn't give me the live application hovers:
{
"type": "java",
"name": "Debug (Launch)-PetClinicApplication<spring-petclinic>",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "org.springframework.samples.petclinic.PetClinicApplication",
"projectName": "spring-petclinic",
"vmArgs": "-Dspring.jmx.enabled=true -Dspring.application.admin.enabled=true"
}
@evowilliamson That's odd I just tried it myself. Here's the complete contents of my launch.json file for reference:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)-PetClinicApplication<spring-petclinic>",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "org.springframework.samples.petclinic.PetClinicApplication",
"projectName": "spring-petclinic",
"args": "",
"vmArgs": [ "-Dspring.jmx.enabled=true", "-Dspring.application.admin.enabled=true" ]
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 0
}
]
}
I launched the Java app via the 'Run' codelens that appears in the main '.java' file next to the 'main' method. This launched fine. I then connected to the process using jconsole and verified on its 'VM Summary' tab that the vmarguments were present and they were. Finally, I use the 'Manage Live Boot Process Connections' command to connect to the process for live data... and live hovers started to appear. (E.g. for a concrete example '@SpringBootApplication' annotation in 'PetClinicApplication.java' became highlighted and hovering over it revealed expected information).
Aha! Okay so when I launch with the above launch.json from the Boot Dashboard 'play' button instead of using the 'Run' codelens then I do get an error. So maybe this could be a bug in the Boot Dashboard.
I suspect the boot dash launch may be passing something funky for the vmarguments. Unfortunately its not that easy to check what was passed as, when the process errors it exits and so I don't get the chance to connect jconsole to take a look.
Okay, I just put a waitloop in the start of my main method so process doesn't error and I have time to inspect what's in JVM args. This is what I found for vmArgs:
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=35473 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dspring.application.admin.enabled=true -Dspring.jmx.enabled=true,-Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8
Looks like Boot dashboard launch (or something else?) added some arguments of its own and then merged in the ones from our launch.json file. But in doing so it put a , between -Dspring.jmx.enable=true and -Dspring.application.admin.enabled=true. This of course changes the meaning of those arguments, and that causes the error in spring boot.
I don't think this is a bug in STS 4, but I'll follow up on this and try and get this properly debugged/fixed.
As a workaround for now, I think you can just omit the second vm argument. "-Dspring.application.admin.enabled=true" because boot dash also sets that already, so its kind of redundant for you/us to set it as well. When we only set a single argument, no spurrious comma is added and everything seems to work fine.
For reference, this launch.json file works for me (with Boot Dash launch):
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)-PetClinicApplication<spring-petclinic>",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "org.springframework.samples.petclinic.PetClinicApplication",
"projectName": "spring-petclinic",
"args": "",
"vmArgs": "-Dspring.jmx.enabled=true"
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 0
}
]
}
I also tried putting all the VMArgs into a single string and that also appears to work fine. It does add the -Dspring.application.admin.enabled=true part twice, but that seems to have no ill effect. I am able to connect to the process and get live hovers.
Anyhow... how it deals with the arguments when placed in a list is still a bug.
For reference, this launch.json file works for me (with Boot Dash launch):
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "java", "name": "Debug (Launch)-PetClinicApplication<spring-petclinic>", "request": "launch", "cwd": "${workspaceFolder}", "console": "internalConsole", "stopOnEntry": false, "mainClass": "org.springframework.samples.petclinic.PetClinicApplication", "projectName": "spring-petclinic", "args": "", "vmArgs": "-Dspring.jmx.enabled=true" }, { "type": "java", "name": "Debug (Attach)", "request": "attach", "hostName": "localhost", "port": 0 } ] }
Just using the single
"vmArgs": "-Dspring.jmx.enabled=true"
does the trick for me!
@kdvolder
As far as I know, Live Hover information is one of the most appealing features. Since it has been blocked by the upstream project (spring-boot), can we add some user guides into README section live-application-information-hovers. E.g., something like:
鈿狅笍 To get the live hover info working, you have to add
"vmArgs": "-Dspring.jmx.enabled=true"mannually in launch.json, or launch the app directly from the boot dashboard extension.
I think it will be helpful when others have the same problem.
@Eskibear Totally agree, I updated the VSCode readme in https://github.com/spring-projects/sts4/commit/3dcb2d429ebfefbee8072b5cf2d81526e30ed7f4
Most helpful comment
For reference, this launch.json file works for me (with Boot Dash launch):