OQL查询查找抱着特定bean的Spring ApplicationContext

时间:2017-03-23 08:11:56

标签: spring heap oql

我使用Spring Boot并且在bean实例化时遇到问题(他们创建了两次)。

如何在OQL查询中从bean引用中找到对ApplicationContext的引用?换句话说,找出给定bean的上下文。

PS VisualVM中的基本故障排除查询:

heap.objects("org.springframework.context.support.AbstractApplicationContext")
heap.objects("org.springframework.core.io.DefaultResourceLoader")

1 个答案:

答案 0 :(得分:0)

ApplicationContext ::

的bean名称查找bean实例
map(heap.objects("org.springframework.context.support.AbstractApplicationContext"), function(it) {
  var fact = it.beanFactory;
  var tbl = fact.singletonObjects.table;
  var beans = map(filter(tbl, "it && /Step$/.test(it.key)"), "{key: it.key, val: it.val}");
  return {ctx: it, beans: beans};
})

ApplicationContext ::

的类名查找bean实例
map(heap.objects("org.springframework.context.support.AbstractApplicationContext"), function(it) {
  var fact = it.beanFactory;
  var tbl = fact.singletonObjects.table;
  var beans = map(filter(tbl, "it && /^com.bigbrother/.test(classof(it.val).name)"), "{key: it.key, val: it.val}");
  return {ctx: it, beans: beans};
})

如果Spring更改了底层实现,则应调整这些查询。寻找字段:

heap.objects("org.springframework.context.support.AbstractApplicationContext")