具体问题
在IDEA运行SpringBoot项目,可以正常运行但是切换到Actuator标签(旧版IDEA是Endpoints)查看SpringBoot应用的状态信息时就会出现下面的提示:
Failed to check application ready state:AttachProvider for the vm is not found. Press Refresh button to reinit ready state checking
并且在SpringBoot项目运行过程中IDEA的Event log中会一直出现
Failed to retrieve application JMX service URL
。
在百度搜索出的原因就是:IDEA和Springboot 项目没有在同一JVM 环境下运行,使得 IDEA 不能连接到这个AttachProvider
操作系统是win10 20H2版本,由于之前在此版本运行时没出现过问题,并且使用过的多台电脑在此版本也没出现过该问题,所以排除。
2.CPU型号
电脑用的是AMD 5600G,之前听闻说AMD对编程方面指令集什么的好像和Intel有什么不同,可能会出现什么问题,但经过在网上关键字搜索没发现当前问题与AMD相关的帖子。所以排除。
3.IDEA版本
使用的是2021.3.2版本,一度以为是IDEA新版本的BUG,但是也曾在该版本正常运行过,然而我将版本降到2021.3.1、2021.3都没用,排除IDEA版本问题
4.JDK版本
同样,以为是安装的jdk-8u321出问题,降版本到jdk-8u202,还是不行,排除JDK版本问题
寻找解决方案
1.百度上找到的解决方案有两种,一种是给每个SpringBoot项目的VM参数加上三行启动的参数,但是如果是微服务项目,每个都加上这参数,显然有些麻烦。另一种是将本地的JDK换成IDEA的JDK,但是感觉这样的局限性很大,并不能很好解决问题(主要是找不到IDEA JDK的下载地址)。
2.用Bing搜索,发现了新世界!!发现了一个在youtrack(好像是Jetbrains专门搜集自家IDE问题的论坛)的帖子
Spring-Boot applications no longer display endpoints
在三年前就报道了这个问题。下面Mike Hill大佬非常长的回答引起了我的注意:
Manually assigning JMX ports to each run configuration is not maintainable for our team, so I spent a bunch of (too much) time trying to figure this out today. The solution was stupidly simple, but wildly unintuitive:
Make sure that the case of the username portion of the %TMP%/hsperfdata_<username> directory matches the username used by your OS. You can find your user in a number of places. A simple one is the "User name" column in in Task Manager -> Details. E.g., if your username is "JohnDoe", but the directory is %TMP%/hsperfdata_johndoe, you must change it to hsperfdata_JohnDoe. Alternatively, you can delete this directory and it should be recreated with the proper case.
This seems to be a JDK issue rather than an IntelliJ issue. Not sure if JetBrains can fix this, but maybe they could add a warning.