From b78f29d15f8dbea04ffddbb11beab743d4ba686a Mon Sep 17 00:00:00 2001 From: Jermaine Hua Date: Tue, 14 May 2024 10:34:35 +0800 Subject: [PATCH] Fix beans infomation lost parentId (#1319) 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 db297c5eb..ec1710977 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 @@ -60,19 +60,33 @@ public IsleBeansEndpoint(ConfigurableApplicationContext context, @Override public BeansEndpoint.BeansDescriptor beans() { BeansEndpoint.BeansDescriptor beansDescriptor = super.beans(); - Map moduleApplicationContexts = getModuleApplicationContexts(applicationRuntimeModel); + String springParentId = null; + for (Map.Entry entry : beansDescriptor.getContexts() + .entrySet()) { + if (entry.getValue().getParentId() == null) { + springParentId = entry.getKey(); + break; + } + } + + Map moduleApplicationContexts = getModuleApplicationContexts( + applicationRuntimeModel, springParentId); beansDescriptor.getContexts().putAll(moduleApplicationContexts); return beansDescriptor; } - 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) { BeansEndpoint.ContextBeansDescriptor contextBeans = describing((ConfigurableApplicationContext) applicationContext, - descriptor.getSpringParent()); + parentId); if (contextBeans != null) { contexts.put(descriptor.getModuleName(), contextBeans); }