模拟Spring容器的getBean方法(Maven工程)
Spring容器的getBean方法是通过反射机制实现的,下面的测试程序模拟getBean的实现原理.
步骤一:pom.xml文件配置解析XML文件的dom4j.jar

步骤二:XML文件中配置bean标签

步骤三:创建测试类ParseSpringXMLTest,设置成员属性,由于bean标签中没有设置Scope属性,故默认使用singleton创建单例.这里创建一个Map集合保存创建好的对象.

步骤四:创建构造器,初始化成员属性

步骤五:模拟实现getBean方法

步骤六:测试程序

步骤七:控制台输出(完结散花..)

模拟Spring容器的getBean方法(Maven工程)的更多相关文章
- 模拟Spring中的getBean方法
一直知道Spring是运用反射技术的,但具体怎么用呢?今天就模拟下getBean方法. 步骤: 1.用Dom4j解析xml配置文件,取出我们需要的信息 2.遍历Bean节点,根据每个Bean节点的cl ...
- 普通java类获取spring容器bean的方法
很多时候,我们在普通的java类中需要获取spring的bean来做操作,比如,在线程中,我们需要操作数据库,直接通过spring的bean中构建的service就可以完成.无需自己写链接..有时候有 ...
- spring容器的refresh方法分析
spring源码版本5.0.5 Spring容器创建之后,会调用它的refresh方法刷新Spring应用的上下文. 首先整体查看AbstractApplicationContext#refresh源 ...
- spring+struts2+hibernate框架搭建(Maven工程)
搭建Spring 1.porm.xml中添加jar包 <!-- spring3 --> <dependency> <groupId>org.springframew ...
- Spring容器自动调用方法的两种方式
先看一个Spring中Bean的实例化过程: 1.配置文件中指定Bean的init-method参数 <bean class="com.jts.service.UserService& ...
- sping框架(3)— 使用spring容器
spring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.它们都可以代表spring容器,sp ...
- Spring 读书笔记-----使用Spring容器(一)
pring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.他们都可代表Spring容器,Spri ...
- (转)Spring 读书笔记-----使用Spring容器(一)
Spring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.他们都可代表Spring容器,Spr ...
- spring 原理1:java 模拟springIOC容器
本篇博客主要是使用java代码模拟spring的IOC容器,实现依赖注入:当然只是模拟spring容器中简单的一点实现原理而已,加深一些自己对spring框架的底层原理的理解: 使用的技术:dom4j ...
随机推荐
- InnoDB: Error: log file .\ib_logfile0 is of different size 0 10485760 bytes
启动WAMP Server的时候报例如以下的错误: 140618 23:12:32 [Note] Plugin 'FEDERATED' is disabled. 140618 23:12:32 Inn ...
- UVA - 10324 Zeros and Ones
Description Given a string of 0's and 1's up to 1000000 characters long and indices i and j, you are ...
- HDUOJ--2121--Ice_cream’s world II【朱刘算法】不定根最小树形图
链接:http://acm.hdu.edu.cn/showproblem.php? pid=2121 题意:n个顶点,m条边,求从某一点起建立有向图最小生成树而且花费最小.输出最小花费和根节点下标. ...
- excel 字符串拼接 添加 超链接
=HYPERLINK("http://"&C2,"http://"&C2)
- vim插件ctags的安装和使用【转】
本文转载自:http://blog.csdn.net/g_brightboy/article/details/16830395 [ctags功能]: 为源码的变量/对象.结构体/类.函数/接口.宏等产 ...
- open_basedir restriction in effect,解决php引入文件权限问题 lnmp
1.配置了虚拟域名 vim /usr/local/nginx/conf/vhost/siemens.conf server { listen 80; #listen [::]:80 default_s ...
- bzoj2125 最短路——仙人掌两点间距离
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2125 仙人掌!模仿 lyd 的代码写的,也算是努力理解了: 主要分成 lca 在环上和不在环 ...
- error: undefined reference to 'property_set (转载)
转自:http://blog.csdn.net/u011589606/article/details/23474241 in the cpp file, please include #include ...
- Linux文件属性相关补充及软硬连接
第1章 文件属性相关 1.1 文件的属性 1.1.1 扩展名 windows 通过扩展名区分不同的类型的文件 linux 扩展名是给人类看的 方便我们区分不同类型文件 .conf 配置文件 ...
- J20170618-hm
番兵(ばんぺい) 哨兵 後始末 善后