bean标签属于beans标签,用来定义Spring容器管理的对象
一:bean标签的格式
<bean/>
<bean> </bean>
二:bean标签的常见属性配置
id: bean的id,可以通过id值获取对应的bean,在一个容器中id值唯一
class:bean的类型,即配置的bean的全路径类名
Eg:
<bean id="bookDao" class="com.itheima.dao.impl.BookDaoImpl"/>
<bean id="bookService" class="com.itheima.service.impl.BookServiceImpl"></bean>
三:bean标签的别名属性配置
name: bean的别名,可定义多个,使用逗号,分号,空格分隔
Eg:
<bean name="service,bookServiceImpl" class="com.itheima.service.impl.BookServiceImpl"/>
<bean name="service;bookServiceImpl" class="com.itheima.service.impl.BookServiceImpl"/>
<bean name="service bookServiceImpl" class="com.itheima.service.impl.BookServiceImpl"/>
四:bean标签的作用范围属性配置
scope: bean的作用范围,可以定义单例(singleton)和非单例(prototype)
Eg:
<bean id="bookDao" class="com.itheima.dao.impl.BookDaoImpl" scope="prototype" />
Note:1.bean默认为单例
2.表现层对象,业务层对象,数据层对象,工具对象适合交给容器进行管理成为bean
3.封装实体的域对象不适合交给容器进行管理成为bean