ApplicationContext context = ... ; // Create your context
String perBeanSummary = "--- Advisors per bean ---\n";
Map<String,Advised> beanMap = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, Advised.class);
Map<Advisor,Set<String>> advisorMap = new HashMap<Advisor, Set<String>>();
// This gathers advisors per bean and beans per advisors,
// and builds the presentation of advisors per bean
for (String beanName : beanMap.keySet()) {
Advised advised = beanMap.get(beanName);
perBeanSummary += beanName + ":\n\t";
for (Advisor advisor : advised.getAdvisors()) {
perBeanSummary += advisor.getAdvice().getClass().getName() + "\n";
Set<String> beans = advisorMap.get(advisor);
if (beans == null) {
beans = new HashSet<String>();
advisorMap.put(advisor, beans);
}
beans.add(beanName);
}
perBeanSummary += "\n";
}
// Builds the presentation of beans per advisor
String perAdvisorSummary = "+++ Beans per advisor +++\n";
for (Advisor advisor : advisorMap.keySet()) {
perAdvisorSummary += advisor.getAdvice().getClass().getName() + "\n";
for (String beanName : advisorMap.get(advisor)) {
perAdvisorSummary += "\t" + beanName + "\n";
}
perAdvisorSummary += "\n";
}
System.out.println(perBeanSummary);
System.out.println(perAdvisorSummary);
Tuesday, September 18, 2007
Advisor summary
It's been a while since the last post, I've been busy with my new assignment that begun right after my vacation. Anyway, here a nifty little routine to quickly get an overview of which beans are woven by what advice, and also what advice weaves which beans in a Spring context:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment