<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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 的入门配置 -->
<bean id="userDAO" class="com.lz.demo1.UserDAOImpl">
<property name="name" value="刘铮"></property>
</bean>
<!--spring 配置生命周期 -->
<bean id="customerDAO" class="com.lz.demo2.CustomerDAOImpl" scope="prototype" init-method="setup" destroy-method="destroy"></bean>
<!--Bean的无参构造方式实例化方式 -->
<bean id ="bean1" class="com.lz.demo3.Bean1"></bean>
<!--静态工厂实例化 -->
<bean id = "bean2" class="com.lz.demo3.BeanFactory" factory-method="createBean2"></bean>
<!--实例工厂实例化 -->
<bean id="bean3Factory" class="com.lz.demo3.Bean3Factory"></bean>
<bean id = "bean3" factory-bean="bean3Factory" factory-method="createBean3"></bean>
<!--无参构造属性注入 -->
<bean id="car" class="com.lz.demo4.Car">
<constructor-arg name="name" value="宝马"></constructor-arg>
<constructor-arg name="price" value="1000000"></constructor-arg>
</bean>
<!--set方法属性注入 -->
<!-- <bean id ="car2" class="com.lz.demo4.Car2">
<property name="name" value="奔驰"></property>
<property name="price" value="122222"></property>
</bean> -->
<!-- 使用p名称空间的方式 -->
<!-- <bean id="car2" class="com.lz.demo4.Car2" p:name='奇瑞QQ' p:price='30000'></bean> -->
<!-- set方法设置对象类型属性 -->
<!-- <bean id="employee" class="com.lz.demo4.Employee">
value:设置普通类型的,ref:设置其他类的id或name
<property name="name" value="刘铮"></property>
<property name="car2" ref="car2"></property>
</bean> -->
<!-- 使用p名称空间的方式 -->
<!-- <bean id="employee" class="com.lz.demo4.Employee" p:name="刘铮" p:car2-ref="car2"></bean> -->
<!-- SpEL属性注入 -->
<bean id = "carInfo" class="com.lz.demo4.CarInfo"></bean>
<bean id ="car2" class="com.lz.demo4.Car2">
<property name="name" value="#{carInfo.name}"></property>
<property name="price" value="#{carInfo.calculatorPrice()}"></property>
</bean>
<bean id="employee" class="com.lz.demo4.Employee">
<property name="name" value="#{'刘铮'}"></property>
<property name="car2" value="#{car2}"></property>
</bean>
<bean id="collectionBean" class="com.lz.demo5.CollectionBean">
<property name="arrs">
<list>
<value>张三</value>
<value>李四</value>
<value>刘铮</value>
</list>
</property>
<property name="list">
<list>
<value>张三</value>
<value>李四</value>
<value>刘铮</value>
</list>
</property>
<property name="set">
<set>
<value>set1</value>
<value>set2</value>
<value>set3</value>
</set>
</property>
<property name="map">
<map>
<entry key="111" value="aaa"/>
<entry key="222" value="bbb"/>
<entry key="333" value="ccc"/>
</map>
</property>
</bean>
</beans>
Spring4的IOC控制反转xml方式
最新推荐文章于 2024-06-17 21:45:29 发布