SpringBean_获取Spring加载的所有bean(实践)
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
SpringBean_获取Spring加载的所有bean(实践)的更多相关文章
- Dubbo实践(六)Spring加载Bean流程
根据上一小节对于spring扩展schema的介绍,大概可以猜到dubbo中相关的内容是如何实现的. 再来回顾Dubbo实践(一)中定义的dubbo-provider.xml: <?xml ve ...
- Spring加载流程源码分析03【refresh】
前面两篇文章分析了super(this)和setConfigLocations(configLocations)的源代码,本文来分析下refresh的源码, Spring加载流程源码分析01[su ...
- Spring加载properties文件的两种方式
在项目中如果有些参数经常需要修改,或者后期可能需要修改,那我们最好把这些参数放到properties文件中,源代码中读取properties里面的配置,这样后期只需要改动properties文件即可, ...
- spring加载jar包中多个配置文件(转)
转自:http://evan0625.iteye.com/blog/1598366 在使用spring加载jar包中的配置文件时,不支持通配符,需要一个一个引入,如下所示: Java代码 <co ...
- 【Spring 源码】Spring 加载资源并装配对象的过程(XmlBeanDefinitionReader)
Spring 加载资源并装配对象过程 在Spring中对XML配置文件的解析从3.1版本开始不再推荐使用XmlBeanFactory而是使用XmlBeanDefinitionReader. Class ...
- 监听spring加载完成后事件
有这个想法是在很早以前了,那时的我没有接触什么缓存技术,只知道hibernate有个二级缓存.没有用过memcache,也没有使用过redis. 只懂得将数据放到数组里或者集合里,一直不去销毁它(只有 ...
- spring加载资源文件中classpath*与classpath的区别
在spring和MyBatis继承的时候,配置mapperLocations.一开始配置是这样的. 需要加载路径为com/thomas/base/mapper和com/thomas/bu/mapper ...
- 【Java Web开发学习】Spring加载外部properties配置文件
[Java Web开发学习]Spring加载外部properties配置文件 转载:https://www.cnblogs.com/yangchongxing/p/9136505.html 1.声明属 ...
- spring加载配置文件
spring加载配置文件 1.把applicationContext.xml直接放在WEB-INF/classes下,spring会采用默认的加载方式2.采用在web.xml中配置ContextLoa ...
随机推荐
- Android 拍照后保证保证图片不失真,进行压缩
今天在网上找了一下参考,得出把图片压缩至KB 其他不想多说.直接上代码 拍完照后调用下面代码 BitmapUtils.compressBitmap(photoPath, photoPath, 640) ...
- swift实现饭否应用客户端源码
swift 版 iOS 饭否客户端 源码下载:http://code.662p.com/view/13318.html 饭否是中国大陆地区第一家提供微博服务的网站,被称为中国版Twitter.用户可通 ...
- 开始使用 UIAlertController 吧
UIAlertView 与 UIActionSheet UIAlertView 样式 实现 - (void)showAlertView { self.alertView = [[UIAlertView ...
- SQL2008使用json.net实现XML与JSON互转
借助CLR,首先实现字符串的互转,然后使用存储过程实现JSON2table public class JsonFunction { /// <summary> ...
- 关于Ruby常用语法案例累积
变量问题: 类变量和方法变量的区别是什么? 类变量:可以直接使用 方法变量:需要实例化后,才能使用该变量 案例一: class Person @@name = "Tom" @@na ...
- SQL*Plus中替换变量与定义变量
替换变量 SQL*Plus中的替换变量又叫替代变量,它一般用来临时存储相关数据:在SQL语句之间传递值.一般使用&或&&前缀来指定替换变量. 关于使用替换变量,一般是利用其创建 ...
- [经验]Textbox 做日志记录,
private void Log(string msg) { txtLog.MaxLength = ; txtLog.AppendText(msg); } 起因:在Winform中用Textbox显示 ...
- C# XML技术总结之XDocument 和XmlDocument
引言 虽然现在Json在我们的数据交换中越来越成熟,但XML格式的数据还有很重要的地位. C#中对XML的处理也不断优化,那么我们如何选择XML的这几款处理类 XmlReader,XDocument ...
- 【WPF系列】Textbox
Style定义实例 给Textbox定义一个阴影效果. <Style x:Key="{x:Type TextBox}" TargetType="{x:Type Te ...
- C#创建委托实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyDe ...