一、bean的实例化方法有3种,

1、构造器实例化

2、静态工厂方法实例化

3、实例工厂方法实例化

二、用构造器来实例化

<bean id="ShunDao" class="test.FTPDAO"  >

id或者name用于指定bean的名称,class用于指定bean的类型

三、静态工厂方法实例化

<bean id="ShunDao" class="test.FTPDAO" factory-method="getInstance">

factory-method用于指定工厂中创建Bean对象的方法,必须static

四、实例工厂方法实例化

<bean id="cal1" class="java.util.Calendar" factory-method="getInstance"></bean>
<bean id="cal3" class="java.util.Date" factory-bean="cal1" factory-method="getTime"></bean>

------------------------------------>>>>>>>>>>>>>>>>>>>>>>>>>>

1、命名bean

每个bean都有一个或者多个的的标识符。这些标识符必须在加载他们的容器里边唯一。一个bean经常有且只有一个标识符,但是如果需要超过一个的名字,可以考虑额外的别名。

基于xml的配置源文件,你可以使用id或者name属性去指定bean的标识符,这里有个问题,如果是名字和ID的不一致,内部又是如何处理的?

如果你不想再另外再给他们定义一个别名,你可以指定name属性,利用逗号(,),分号(;)或者空格。spring3.1以前id属性是xsd:ID类型的,这个是唯一的,3.1以后,xml文件是xsd:string这个xml文件不校验,但是spring需要它唯一。

如果一个bean没有明确指定ID或者name,容器将为bean生成一个唯一的名字。但是,如果你想用ref来引用,就必须定义一个名字。

Motivations for not supplying a name are related to using inner beans and autowiring collaborators.

这句话怎么理解??!!!!!!!!

Bean 命名约定,和java一样,用一个小写字符,驼峰式

在一个bean的定义里边,你可以给bean起多于一个的名字,一个ID,多个名字,名字name和别名alias是等价的

2、

Instantiating beans

A bean definition essentially is a recipe for creating one or more objects. The container looks at the recipe for a named bean when asked, and uses the configuration metadata encapsulated by that bean definition to create (or acquire) an actual object.

If you use XML-based configuration metadata, you specify the type (or class) of object that is to be instantiated in the

.

Within the container itself, these bean definitions are represented as BeanDefinition objects, which contain (among other information) the following metadata:

A package-qualified class name: typically the actual implementation class of the bean being defined.
Bean behavioral configuration elements, which state how the bean should behave in the container (scope, lifecycle callbacks, and so forth).
References to other beans that are needed for the bean to do its work; these references are also called collaborators or dependencies.

合作和依赖有什么区别?
Other configuration settings to set in the newly created object, for example, the number of connections to use in a bean that manages a connection pool, or the size limit of the pool.
This metadata translates to a set of properties that make up each bean definition.

Table 5.1. The bean definition

Property

class Instantiating beans

name Naming beans

scope Bean scopes

constructor arguments Dependency injection

properties Dependency injection

autowiring mode Autowiring collaborators

lazy-initialization mode Lazy-initialized beans

initialization method Initialization callbacks

destruction method Destruction callbacks

In addition to bean definitions that contain information on how to create a specific bean, the ApplicationContext implementations also permit the registration of existing objects that are created outside the container, by users. This is done by accessing the ApplicationContext’s BeanFactory via the method getBeanFactory() which returns the BeanFactory implementation DefaultListableBeanFactory. DefaultListableBeanFactory supports this registration through the methods registerSingleton(..) and registerBeanDefinition(..). However, typical applications work solely with beans defined through metadata bean definitions.

最新文章

  1. C++ 高性能无锁日志系统
  2. css中如何设置字体
  3. 解决HTML5布局,兼容IE问题
  4. excel在一个图表内,显示折线图和柱状图
  5. 【nodejs】json value出现 undefined 将会无法解析 问题来了
  6. linux如何关闭防火墙
  7. [转] Linux下查看文件和文件夹大小
  8. ubuntu gnome vnc
  9. Spark-GraphxAPI学习笔记
  10. (图文实例)用VB.net操作SQLite数据库
  11. matplotlib 中的柱状图
  12. TCP/IP 四次断开
  13. [物理学与PDEs]第3章第2节 磁流体力学方程组 2.3 磁流体力学方程组
  14. pre强制 自动换行
  15. Oracle管理表空间和数据文件详解
  16. ASA5520远程配置 telnet,ssh
  17. unp的hello word
  18. Extjs4 页面加载先白屏后显示的bug解决
  19. gulp + angular + requirejs 简单学习
  20. 基于python的几种排序算法的实现

热门文章

  1. redis web 客户端工具 redis-admin
  2. Could not obtain connection metadata
  3. OpenGL的几何变换4之内观察全景图
  4. ssh批量登录并执行命令(python实现)
  5. MVC HtmlHelper用法大全
  6. iOS开发 cocoapods的安装以及使用
  7. iOS 打包静态类库 lib.a
  8. SAP MM模块之批次管理
  9. HTML5自学笔记[ 15 ]canvas绘图基础6
  10. (14)odoo加载机制