2017-03-23 2 views
0

J'utilise Spring Boot et j'ai un problème avec l'instanciation des beans (ils ont été créés deux fois).Requête OQL pour trouver Spring ApplicationContext contenant le bean spécifique

Comment trouver une référence à ApplicationContext à partir d'une référence de bean dans une requête OQL? En d'autres termes, découvrez le contexte du haricot donné.

PS requête de dépannage de base en VisualVM:

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

Répondre

0

Trouvez des instances de haricots par nom de haricot par ApplicationContext ::

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}; 
}) 

Trouvez des instances de haricots par nom de classe par ApplicationContext ::

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}; 
}) 

Si Spring modifie l'implémentation sous-jacente, ces requêtes doivent être ajustées. Recherchez les champs:

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