1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | private static ApplicationContext ctx; public static void main(String[] args) { try { ctx = new ClassPathXmlApplicationContext( new String[]{ "classpath:spring/spring-dao.xml" , "classpath:spring/spring-biz.xml" , "classpath:spring/spring-service.xml" , "classpath:spring/spring.xml" }); listAllSpringBeans(); } catch (Exception e) { e.printStackTrace(); } } private static void listAllSpringBeans() { String[] beanNames = ctx.getBeanDefinitionNames(); int allBeansCount = ctx.getBeanDefinitionCount(); System.out.println( "所有beans的数量是:" + allBeansCount); for (String beanName : beanNames) { Class<?> beanType = ctx.getType(beanName); Package beanPackage = beanType.getPackage(); Object bean = ctx.getBean(beanName); System.out.println( "BeanName:" + beanName); System.out.println( "Bean的类型:" + beanType); System.out.println( "Bean所在的包:" + beanPackage); System.out.println( "\r\n" ); } } |
二、查询结果
所有beans的数量是:32
BeanName:org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0
Bean的类型:class org.springframework.context.support.PropertySourcesPlaceholderConfigurer
Bean所在的包:package org.springframework.context.support
BeanName:dataSource
Bean的类型:class com.alibaba.druid.pool.DruidDataSource
Bean所在的包:package com.alibaba.druid.pool
BeanName:sqlSessionFactory
Bean的类型:class org.apache.ibatis.session.defaults.DefaultSqlSessionFactory
Bean所在的包:package org.apache.ibatis.session.defaults, mybatis, version 3.3.1
BeanName:org.mybatis.spring.mapper.MapperScannerConfigurer#0
Bean的类型:class org.mybatis.spring.mapper.MapperScannerConfigurer
Bean所在的包:package org.mybatis.spring.mapper, mybatis-spring, version 1.2.3
BeanName:transactionManager
Bean的类型:class org.springframework.jdbc.datasource.DataSourceTransactionManager
Bean所在的包:package org.springframework.jdbc.datasource
BeanName:txAdvice
Bean的类型:class org.springframework.transaction.interceptor.TransactionInterceptor
Bean所在的包:package org.springframework.transaction.interceptor
BeanName:org.springframework.aop.config.internalAutoProxyCreator
Bean的类型:class org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator
Bean所在的包:package org.springframework.aop.aspectj.autoproxy
BeanName:manager
Bean的类型:class org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor
Bean所在的包:package org.springframework.aop.support
BeanName:org.springframework.transaction.config.internalTransactionalEventListenerFactory
Bean的类型:class org.springframework.transaction.event.TransactionalEventListenerFactory
Bean所在的包:package org.springframework.transaction.event
BeanName:org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0
Bean的类型:class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource
Bean所在的包:package org.springframework.transaction.annotation
BeanName:org.springframework.transaction.interceptor.TransactionInterceptor#0
Bean的类型:class org.springframework.transaction.interceptor.TransactionInterceptor
Bean所在的包:package org.springframework.transaction.interceptor
BeanName:org.springframework.transaction.config.internalTransactionAdvisor
Bean的类型:class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor
Bean所在的包:package org.springframework.transaction.interceptor
BeanName:gossip.dub.service
Bean的类型:class com.alibaba.dubbo.config.ApplicationConfig
Bean所在的包:package com.alibaba.dubbo.config, Dubbo, version 2.5.3
BeanName:com.alibaba.dubbo.config.RegistryConfig
Bean的类型:class com.alibaba.dubbo.config.RegistryConfig
Bean所在的包:package com.alibaba.dubbo.config, Dubbo, version 2.5.3
BeanName:dubbo
Bean的类型:class com.alibaba.dubbo.config.ProtocolConfig
Bean所在的包:package com.alibaba.dubbo.config, Dubbo, version 2.5.3
BeanName:org.gossip.dub.facade.ISeckillService
Bean的类型:class com.alibaba.dubbo.config.spring.ServiceBean
Bean所在的包:package com.alibaba.dubbo.config.spring, Dubbo, version 2.5.3
BeanName:seckillService
Bean的类型:class org.gossip.dub.service.impl.SeckillService
Bean所在的包:package org.gossip.dub.service.impl
BeanName:org.gossip.dub.facade.ISysAdminInfoService
Bean的类型:class com.alibaba.dubbo.config.spring.ServiceBean
Bean所在的包:package com.alibaba.dubbo.config.spring, Dubbo, version 2.5.3
BeanName:sysAdminInfoService
Bean的类型:class org.gossip.dub.service.impl.SysAdminInfoService
Bean所在的包:package org.gossip.dub.service.impl
BeanName:seckillManager
Bean的类型:class org.gossip.dub.manager.SeckillManager$$EnhancerBySpringCGLIB$$2144142f
Bean所在的包:package org.gossip.dub.manager
BeanName:sysAdminInfoManager
Bean的类型:class org.gossip.dub.manager.SysAdminInfoManager$$EnhancerBySpringCGLIB$$c2215ec8
Bean所在的包:package org.gossip.dub.manager
BeanName:org.springframework.context.annotation.internalConfigurationAnnotationProcessor
Bean的类型:class org.springframework.context.annotation.ConfigurationClassPostProcessor
Bean所在的包:package org.springframework.context.annotation
BeanName:org.springframework.context.annotation.internalAutowiredAnnotationProcessor
Bean的类型:class org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
Bean所在的包:package org.springframework.beans.factory.annotation
BeanName:org.springframework.context.annotation.internalRequiredAnnotationProcessor
Bean的类型:class org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor
Bean所在的包:package org.springframework.beans.factory.annotation
BeanName:org.springframework.context.annotation.internalCommonAnnotationProcessor
Bean的类型:class org.springframework.context.annotation.CommonAnnotationBeanPostProcessor
Bean所在的包:package org.springframework.context.annotation
BeanName:org.springframework.context.event.internalEventListenerProcessor
Bean的类型:class org.springframework.context.event.EventListenerMethodProcessor
Bean所在的包:package org.springframework.context.event
BeanName:org.springframework.context.event.internalEventListenerFactory
Bean的类型:class org.springframework.context.event.DefaultEventListenerFactory
Bean所在的包:package org.springframework.context.event
BeanName:org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor
Bean的类型:class org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor
Bean所在的包:package org.springframework.context.annotation
BeanName:org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor
Bean的类型:class org.springframework.context.annotation.ConfigurationClassPostProcessor$EnhancedConfigurationBeanPostProcessor
Bean所在的包:package org.springframework.context.annotation
BeanName:ISecKillMapper
Bean的类型:interface org.gossip.dub.dao.ISecKillMapper
Bean所在的包:package org.gossip.dub.dao
BeanName:ISuccessKilledMapper
Bean的类型:interface org.gossip.dub.dao.ISuccessKilledMapper
Bean所在的包:package org.gossip.dub.dao
BeanName:ISysAdminInfoMapper
Bean的类型:interface org.gossip.dub.dao.ISysAdminInfoMapper
Bean所在的包:package org.gossip.dub.dao