| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd">
- <!--创建spring配置文件,配置对应的类,作为spring管理的bean-->
- <!--
- bean是专门指在IOC容器里的对象
- bean标签:表示配置bean
- id属性:是给bean取个名字
- class属性:表示给bean定义实际的类型
- name属性:为这个bean取别名
- scope属性:定义bean的作用范围,可以选择:单例(singleton)、非单例(prototype),默认scope属性的值是singleton单例模式
- request
- session
- application
- websocket....
- -->
- <bean id="UserMapper" name="userMapper,userMapperImpl,userMapperImpl1" class="com.sf.ioc.mapper.UserMapperImpl" scope="singleton" />
- <!--配置service和mapper之间的关系-->
- <bean id="UserService" name="userService,userServiceImpl1" class="com.sf.ioc.service.impl.UserServiceImpl" scope="prototype">
- <!--
- property标签:配置当前的bean的属性
- name属性:对应着具体的属性变量
- ref属性:对应着要参照的是哪一个bean
- -->
- <property name="userMapper" ref="UserMapper"/>
- </bean>
- <bean id="StudentService" name="studentService"
- class="com.sf.ioc.factory.StudentServiceFactory" factory-method="getStudentService" />
- <!--先创建工厂bean-->
- <bean id="productServiceFactory" class="com.sf.ioc.factory.ProductServiceFactory"/>
- <!--创建productServiceBean的时候,引入工厂bean-->
- <bean id="ProductService" name="productService"
- factory-bean="productServiceFactory" factory-method="getProductService"/>
- <!--
- init-method属性:表示这个bean初始化后立刻要执行的方法
- destroy-method属性:表示这个bean在销毁之前要执行的方法
- -->
- <bean id="TeaService" name="teaService"
- class="com.sf.beanLifeCycle.service.impl.TeaServiceImpl"/>
- </beans>
|