Skip to content

Commit

Permalink
Fix beans information lost parentId (#1320)
Browse files Browse the repository at this point in the history
Signed-off-by: JermaineHua <crazyhzm@apache.org>
  • Loading branch information
CrazyHZM authored May 14, 2024
1 parent d65c12b commit 6318683
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,33 @@ public ApplicationBeans beans() {
ApplicationBeans applicationBeans = super.beans();
ApplicationRuntimeModel applicationRuntimeModel = context.getBean(
SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class);
Map<String, ContextBeans> moduleApplicationContexts = getModuleApplicationContexts(applicationRuntimeModel);

String springParentId = null;
for (Map.Entry<String, ContextBeans> entry : applicationBeans.getContexts().entrySet()) {
if (entry.getValue().getParentId() == null) {
springParentId = entry.getKey();
break;
}
}

Map<String, ContextBeans> moduleApplicationContexts = getModuleApplicationContexts(
applicationRuntimeModel, springParentId);
applicationBeans.getContexts().putAll(moduleApplicationContexts);
return applicationBeans;
}

private Map<String, ContextBeans> getModuleApplicationContexts(ApplicationRuntimeModel applicationRuntimeModel) {
private Map<String, ContextBeans> getModuleApplicationContexts(ApplicationRuntimeModel applicationRuntimeModel,String springParentId) {
Map<String, ContextBeans> contexts = new HashMap<>();
List<DeploymentDescriptor> 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);
}
Expand Down

0 comments on commit 6318683

Please sign in to comment.