@Test public void logBeansInContext() { DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory; if (factory != null) { logger.debug("Bean Factory: '{}'", factory); } if (applicationContext.getParent() != null) { logger.debug("Bean Factory: '{}'", applicationContext.getParentBeanFactory()); } logger.debug("******************************************************************************"); String[] beans = applicationContext.getBeanDefinitionNames(); for (String o : beans) { logger.debug("________________________"); logger.debug("BEAN id: '{}'", o); logger.debug("\tType: '{}'", applicationContext.getType(o)); String[] aliases = applicationContext.getAliases(o); if (factory.isFactoryBean(o)) logger.debug("\tFACTORY"); if (aliases != null && aliases.length > 0) { for (String a : aliases) { logger.debug("\tAliased as: '{}'", a); } } if (factory.getBeanDefinition(o).isAbstract()) { logger.debug("\tABSTRACT"); } else { if (applicationContext.isPrototype(o)) logger.debug("\tScope: 'Prototype'"); if (applicationContext.isSingleton(o)) logger.debug("\tScope: 'Singleton'"); Annotation[] annotations = applicationContext.getBean(o).getClass().getAnnotations(); if (annotations != null && annotations.length > 0) { logger.debug("\tAnnotations:"); for (Annotation annotation : annotations) { logger.debug("\t\t'{}'", annotation.annotationType()); } } if (!applicationContext .getBean(o) .toString() .startsWith(applicationContext.getType(o).toString() + "@")) { logger.debug("\tContents: {}", applicationContext.getBean(o).toString()); } } } logger.debug("******************************************************************************"); logger.debug("*** Number of Beans={} ***", applicationContext.getBeanDefinitionCount()); logger.debug("*** Number of Bean Post Processors={} ***", factory.getBeanPostProcessorCount()); logger.debug("******************************************************************************"); }
/** * 如果给定的bean名字在bean定义中有别名,则返回这些别名 * * @param name * @return * @throws NoSuchBeanDefinitionException */ public static String[] getAliases(String name) throws NoSuchBeanDefinitionException { return applicationContext.getAliases(name); }
public String[] getAliases(String arg0) { return applicationContext.getAliases(arg0); }