【SpringInAction】 基本Bean装配 Demo

引用
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-4.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
	<bean id="sonnet29" class="com.lh.springtest02.section2.Sonnet29" />  
	<bean id="saxophone" class="com.lh.springtest02.section2.Saxophone" /> 
	<bean id="harmonica" class="com.lh.springtest02.section2.Harmonica" /> 
	<bean id="guitar" class="com.lh.springtest02.section2.Guitar" /> 
	<bean id="hank" class="com.lh.springtest02.section2.OneManBand">
		<property name="instruments">
		<!--
 		    <list>
				<ref bean="saxophone"/>
				<ref bean="guitar"/>
				<ref bean="harmonica"/>
			</list> -->
			<set>
				<ref bean="saxophone"/>
				<ref bean="harmonica"/>
				<ref bean="guitar"/>
				<ref bean="guitar"/>
			</set>
		</property>
	</bean>
	<bean id="hank2" class="com.lh.springtest02.section2.OneManBand2">
		<property name="instruments">
			<map>
				<entry key="guitar" value-ref="guitar" />
				<entry key="harmonica" value-ref="harmonica" />
				<entry key="saxophone" value-ref="saxophone" />
			</map>
		</property>
	</bean>
	
	<bean id="hankprop" class="com.lh.springtest02.section2.OneManBandProp">
		<property name="instruments">
			<props>
				<prop key="GUITAR">GUITAR GUITAR GUITAR</prop>
				<prop key="HARMONICA">HARMONICA HARMONICA HARMONICA</prop>
				<prop key="SAXOPHONE">SAXOPHONE SAXOPHONE SAXOPHONE</prop>
			</props>
		</property>
	</bean>
	
	<bean id="duke" class="com.lh.springtest02.section2.Juggler">
		<constructor-arg value="15"></constructor-arg>
	</bean> 
	<bean id="duke2" class="com.lh.springtest02.section2.PoeticJuggler">
		<constructor-arg value="16" />
		<constructor-arg ref="sonnet29"/>
	</bean>     
	
	<bean id="kenny" class="com.lh.springtest02.section2.Instrumentalist">
		<!-- 
		<property name="song" value="Jinggle Bells" /> 
		<property name="age" value="28"/>
		-->
		<property name="song"><null/></property>
		<property name="age" value="28"/>
		<property name="instrument" ref="saxophone" />
		<!-- <property name="instrument">
			<bean class="com.lh.springtest02.section2.Saxophone" />
		</property> -->
	</bean>
</beans>  
       

你可能感兴趣的:(bean DI Spring)