具體問(wèn)題
在IDEA運(yùn)行SpringBoot項(xiàng)目购对,可以正常運(yùn)行但是切換到Actuator標(biāo)簽(舊版IDEA是Endpoints)查看SpringBoot應(yīng)用的狀態(tài)信息時(shí)就會(huì)出現(xiàn)下面的提示:
Failed to check application ready state:AttachProvider for the vm is not found. Press Refresh button to reinit ready state checking
并且在SpringBoot項(xiàng)目運(yùn)行過(guò)程中IDEA的Event log中會(huì)一直出現(xiàn)Failed to retrieve application JMX service URL
驹闰。
問(wèn)題原因
在百度搜索出的原因就是:IDEA和Springboot 項(xiàng)目沒(méi)有在同一JVM 環(huán)境下運(yùn)行噩茄,使得 IDEA 不能連接到這個(gè)AttachProvider
問(wèn)題排查
- Windows10版本
操作系統(tǒng)是win10 20H2版本,由于之前在此版本運(yùn)行時(shí)沒(méi)出現(xiàn)過(guò)問(wèn)題,并且使用過(guò)的多臺(tái)電腦在此版本也沒(méi)出現(xiàn)過(guò)該問(wèn)題,所以排除热芹。
2.CPU型號(hào)
電腦用的是AMD 5600G,之前聽(tīng)聞?wù)fAMD對(duì)編程方面指令集什么的好像和Intel有什么不同惨撇,可能會(huì)出現(xiàn)什么問(wèn)題伊脓,但經(jīng)過(guò)在網(wǎng)上關(guān)鍵字搜索沒(méi)發(fā)現(xiàn)當(dāng)前問(wèn)題與AMD相關(guān)的帖子。所以排除魁衙。
3.IDEA版本
使用的是2021.3.2版本报腔,一度以為是IDEA新版本的BUG,但是也曾在該版本正常運(yùn)行過(guò)剖淀,然而我將版本降到2021.3.1榄笙、2021.3都沒(méi)用,排除IDEA版本問(wèn)題
4.JDK版本
同樣祷蝌,以為是安裝的jdk-8u321出問(wèn)題茅撞,降版本到j(luò)dk-8u202,還是不行巨朦,排除JDK版本問(wèn)題
尋找解決方案
1.百度上找到的解決方案有兩種米丘,一種是給每個(gè)SpringBoot項(xiàng)目的VM參數(shù)加上三行啟動(dòng)的參數(shù),但是如果是微服務(wù)項(xiàng)目糊啡,每個(gè)都加上這參數(shù)拄查,顯然有些麻煩。另一種是將本地的JDK換成IDEA的JDK棚蓄,但是感覺(jué)這樣的局限性很大堕扶,并不能很好解決問(wèn)題(主要是找不到IDEA JDK的下載地址)。
2.用Bing搜索梭依,發(fā)現(xiàn)了新世界I运恪!發(fā)現(xiàn)了一個(gè)在youtrack(好像是Jetbrains專門(mén)搜集自家IDE問(wèn)題的論壇)的帖子Spring-Boot applications no longer display endpoints
在三年前就報(bào)道了這個(gè)問(wèn)題役拴。下面Mike Hill大佬非常長(zhǎng)的回答引起了我的注意:
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.
Mike Hill大佬也覺(jué)得給每個(gè)SpringBoot項(xiàng)目的VM參數(shù)加上三行啟動(dòng)的參數(shù)是不可取的糊探,經(jīng)過(guò)大佬的研究發(fā)現(xiàn),發(fā)現(xiàn)問(wèn)題出在%TMP%/hsperfdata_<username>文件夾河闰,%TMP%/hsperfdata_<username>的username要和系統(tǒng)用戶名的大小寫(xiě)一致科平,按照他的思路我找到了我電腦上的C:\Users\lxc\AppData\Local\Temp\hsperfdata_lxc文件夾,但是發(fā)現(xiàn)hsperfdata_lxc的username部分和我電腦的用戶名一樣姜性,沒(méi)問(wèn)題啊瞪慧,于是我試探性將該文件夾刪除,重新運(yùn)行項(xiàng)目部念,然后就沒(méi)問(wèn)題了F谩0惫健!正常運(yùn)行J改濉C偶荨射赛!
(其實(shí)一開(kāi)始沒(méi)看懂Mike Hill大佬說(shuō)的是什么多柑,看完他的回答,然后去他給的鏈接jconsole - Local java processes are grayed when trying to connect via JMX 看完后才明白大概是怎么回事
)
最終解決方案
將C:\Users{username}\AppData\Local\Temp\hsperfdata_{username}這個(gè)文件刪掉楣责,username代表操作系統(tǒng)的用戶名竣灌。