GH-331 - Avoid processing infrastructure beans in observability infrastructure.

We now skip infrastructure role beans during the processing of beans that could be subject to inter-module interaction observability. Previously, we could accidentally trigger a dependency cycle if the ModuleTracingBeanPostProcessor triggered the initial creation of AutoConfigurationPackages as that would then trigger the PostProcessor in turn which would try to lookup the ACP bean again to determine whether it should post process that to apply observability.
This commit is contained in:
Oliver Drotbohm
2023-10-16 13:34:41 +02:00
parent 0810d8025e
commit d14ba59837
3 changed files with 30 additions and 8 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.modulith.runtime.autoconfigure;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -38,6 +39,7 @@ class SpringBootApplicationRuntime implements ApplicationRuntime {
private final ApplicationContext context;
private Class<?> mainApplicationClass;
private List<String> resolvedAutoConfigurationPackages;
/**
* Creates a new {@link SpringBootApplicationRuntime} for the given {@link ApplicationContext}.
@@ -113,6 +115,15 @@ class SpringBootApplicationRuntime implements ApplicationRuntime {
}
return fqn.startsWith(applicationClass.getPackage().getName())
|| AutoConfigurationPackages.get(context).stream().anyMatch(pkg -> fqn.startsWith(pkg));
|| getAutoConfigurationPackages().stream().anyMatch(pkg -> fqn.startsWith(pkg));
}
private List<String> getAutoConfigurationPackages() {
if (resolvedAutoConfigurationPackages == null) {
this.resolvedAutoConfigurationPackages = AutoConfigurationPackages.get(context);
}
return resolvedAutoConfigurationPackages;
}
}