-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Closed
Description
We have a spring boot application with context hierarchy and where we add only the auto configuration classes we need.
the beans endpoint does not list beans from parent, i had to override the beans endpoint with a custor one that looks like that:
@ConfigurationProperties(prefix = "endpoints.beans", ignoreUnknownFields = false)
public class TaboolaBeansEndpoint extends BeansEndpoint {
private final BELiveBeansView liveBeansView = new BELiveBeansView();
private final JsonParser parser = JsonParserFactory.getJsonParser();
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
if (context.getEnvironment()
.getProperty(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME) == null) {
this.liveBeansView.setApplicationContext(context);
}
}
@Override
public List<Object> invoke() {
return this.parser.parseList(this.liveBeansView.getSnapshotAsJson());
}
public static final class BELiveBeansView extends LiveBeansView{
Set<ConfigurableApplicationContext> contexts = new HashSet<ConfigurableApplicationContext>();
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
Assert.isTrue(applicationContext instanceof ConfigurableApplicationContext,
"ApplicationContext does not implement ConfigurableApplicationContext");
if (applicationContext != null) {
ApplicationContext current = applicationContext;
while(current != null){
Assert.isTrue(applicationContext instanceof ConfigurableApplicationContext,
"ApplicationContext does not implement ConfigurableApplicationContext");
contexts.add((ConfigurableApplicationContext) current);
current = current.getParent();
}
}
}
@Override
public String getSnapshotAsJson() {
return generateJson(contexts);
}
}
}Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug