Spring学习一(入门和bean的作用域)
来源:互联网 发布:sql 查询包含字段的表 编辑:程序博客网 时间:2024/06/07 07:00
转载自:http://takeme.iteye.com/blog/2100726
第一
第二、Spring容器中Bean的作用域
1、全局属性
default-lazy-init :该beans下的所有bean 默认延迟初始化行为
default-merge:指定beans下的所有bean默认的mege行为
default-autowire:该beans下的所有bean都默认自动装配行为
default-autowire-candidates:指定beans下所有bean默认是否为自动装配的候选bean
default-init-method:指定beans下的所有bean的默认初始化方法
default-destory-method:指定beans下的所有的bean的默认回eton收方法
注:以上属性去掉default后就是单个bean的特性
2、bean的作用域:
scope=singleton:默认值,单例模式
scope=prototype:每次都会创建对象 ---->只用在web中的每一次回话需要一个唯一的值的情况
嵌套bean
<bean id="UserDaoService" class=""scope=prototype>
<property name="" value> </property>
<constructor-arg name="age" value="18" type="int"/>
<!--内嵌bean->
<property name="UserDao" <bean class=""/> </property>
<property name="userdao1" ref=UserDao> </property>
<ref local="userdao"/>
</bean>
3、详细使用举例
<bean id=" " calss=" " autowire-candidate ="false"> --此bean不参与自动装配
<bean id=" " calss=" " autowire="no"> ---默认不在用自动注入
<bean id=" " calss=" " autowire="byName"> --根据 setName()
<bean id=" " class="" autowire="byType"> --根据 setName(Type type) 如果spring 容器中有多个 Type 的bean 会出异常
<bean id=" " calss=" " autowire="constructor"> ---根据类中的构造函数进行装配
<bean id=" " calss=" " autowire="autodetect"> --用于2.5 3.0以后 交给spring ,决定是使用构造函数还是使用byType
4、给bean注入集合属性
<bean id=""> calss="">
<property name="">
<list>
<value=""></value>
<value=""></value>
</list>
</property>
</bean>
5、bean注入的原则:
用构造方法注入时,要提供构造方法
设值注入的bean,要提供setting注入,可以不提供getter方法
- Spring学习一(入门和bean的作用域)
- Spring入门(5),Bean种类和作用域
- Spring学习(4)--Spring中Bean的作用域
- spring学习笔记(1) 配置spring bean的作用域 创建方法和销毁方法
- Spring 学习笔记 Bean的作用域
- 学习笔记:Spring Bean的作用域
- spring bean的作用域和生命周期
- Spring Bean的生命周期和作用域
- Spring学习笔记(二)Bean的作用域
- Spring框架学习(6):bean的作用域
- Spring 4.0 学习日记(4)--- bean的作用域
- Spring学习(五)-Bean的作用域
- Spring入门学习——设置Bean作用域
- Spring学习笔记(5.Spring Bean装配之Bean的配置项及作用域)
- Spring学习,bean作用域
- Spring bean的作用域(转)
- Spring(六):Bean 的作用域
- Spring bean的作用域(scope)
- Toolbar(标题栏)
- C++独孤九剑第二式——众妙之门(函数处理机制)
- Poj1113 Wall
- Android SQLite数据库添加数据出错 at android.database.sqlite.SQLiteStatement.releaseAndUnlock
- Qt/C++ 继承QWidget setstylesheet解决
- Spring学习一(入门和bean的作用域)
- iOS输出数值控制小数位数
- Java IO模型&NIO
- 鸟哥Java学习之多态、内部类-面向对象
- NodeJS优缺点及适用场景讨论
- JAVA集合 笔记
- 类的构造函数和析构函数
- 鸟哥Java学习之异常-面向对象
- tikz-path