From 63186834f133826e66e05cea0a8e615c0feb1b9f Mon Sep 17 00:00:00 2001 From: Jermaine Hua Date: Tue, 14 May 2024 10:34:00 +0800 Subject: [PATCH] Fix beans information lost parentId (#1320) Signed-off-by: JermaineHua --- .../actuator/beans/IsleBeansEndpoint.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/beans/IsleBeansEndpoint.java b/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/beans/IsleBeansEndpoint.java index 70d046191..49ebb5de1 100644 --- a/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/beans/IsleBeansEndpoint.java +++ b/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/beans/IsleBeansEndpoint.java @@ -57,19 +57,33 @@ public ApplicationBeans beans() { ApplicationBeans applicationBeans = super.beans(); ApplicationRuntimeModel applicationRuntimeModel = context.getBean( SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class); - Map moduleApplicationContexts = getModuleApplicationContexts(applicationRuntimeModel); + + String springParentId = null; + for (Map.Entry entry : applicationBeans.getContexts().entrySet()) { + if (entry.getValue().getParentId() == null) { + springParentId = entry.getKey(); + break; + } + } + + Map moduleApplicationContexts = getModuleApplicationContexts( + applicationRuntimeModel, springParentId); applicationBeans.getContexts().putAll(moduleApplicationContexts); return applicationBeans; } - private Map getModuleApplicationContexts(ApplicationRuntimeModel applicationRuntimeModel) { + private Map getModuleApplicationContexts(ApplicationRuntimeModel applicationRuntimeModel,String springParentId) { Map contexts = new HashMap<>(); List installedModules = applicationRuntimeModel.getInstalled(); installedModules.forEach(descriptor -> { ApplicationContext applicationContext = descriptor.getApplicationContext(); + String parentId = descriptor.getSpringParent(); + if (parentId == null){ + parentId = springParentId; + } if (applicationContext instanceof ConfigurableApplicationContext) { ContextBeans contextBeans = describing((ConfigurableApplicationContext) applicationContext, - descriptor.getSpringParent()); + parentId); if (contextBeans != null) { contexts.put(descriptor.getModuleName(), contextBeans); }