bean裝配樣式大全
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/util
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-init-method=""
default-destroy-method=""
default-autowire="byType"> <!-- 默認自動裝配方式 -->
<util:list id="strArray">
<value>Hello</value>
<value>Welcome</value>
</util:list>
<bean id="duke" class="Juggler" > <constructor-arg value="10"/> </bean>
<bean id="sonnet29" class="Sonnet29" />
<bean id="poeticDuke" class="PoeticJuggler" >
<constructor-arg value="10"/>
<constructor-arg ref="sonnet29"/>
</bean>
<bean id="theStage" class="Stage" factory-method="getInstance"></bean>
<bean id="sonnt29" class="Sonnet29" scope="prototype" /> <!-- 每次請求產生一個新的實例 -->
<bean id="sonnt292" class="Sonnet29" scope="singleton" > <!-- 默認的 只有一個實例 -->
<property name="" value="#{systemEnvironment['HOME']}" /><!-- 系統環境 -->
<property name="bigCites" value="#{cities.?[population gt 10000]}" /><!-- .?[] 查詢運算符 .^[]第一個匹配項 .$[] 最後一個 -->
<property name="bigCites" value="#{cities.![name]}" /><!-- .![] 投影操作 -->
<property name="" value="#{theStage.song}" />
<property name="" value="#{theStage.selectSong()}" />
<property name="" value="#{theStage.selectSong()?.toUpperCase()}" /><!-- null safe -->
<property name="" value="#{T(java.lang.Math).PI}" />
<property name="" value="#{T(java.lang.Math).random() + 20}" />
<property name="validV" value="#{ value matches '[a-z+]'}" />
<property name="validV" value="#{strArray[2] }" />
<property name="" ><null/></property>
<property name="" ref="" />
<property name="" >
<bean class="" />
</property>
<property name="l1">
<list>
<ref bean=''/>
<ref bean=''/>
</list>
</property>
<property name="l2">
<set>
<ref bean=''/>
<ref bean=''/>
</set>
</property>
<property name="l3">
<map>
<entry key='str' value-ref="bean"/>
<entry key='str' value="str"/>
<entry key-ref='bean' value="str"/>
<entry key-ref='bean' value-ref="bean"/>
</map>
</property>
<property name="l4">
<props>
<prop key='str'>str</prop>
</props>
</property>
</bean>
<bean id="s1" class="S1" init-method="" destroy-method=""/>
<util:properties id="settings" location="classpath:settings.properties"/><!-- 加載一個配置文件到settins props -->
<property name='' value='#{settings['key']}'/>
<!-- 將多個配置文件讀取到容器中,交給Spring管理 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- 這裏支持多種尋址方式:classpath和file -->
<value>classpath:/opt/demo/config/demo-db.properties</value>
<!-- 推薦使用file的方式引入,這樣可以將配置和代碼分離 -->
<value>file:/opt/demo/config/demo-mq.properties</value>
<value>file:/opt/demo/config/demo-remote.properties</value>
</list>
</property>
</bean>
<!-- 使用MQ中的配置 -->
<bean id="MQJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">${mq.java.naming.factory.initial}</prop>
</props>
</property>
</bean>
<!-- 自動裝配 -->
<bean id="MQJndiTemplate" class="org.springframework.jndi.JndiTemplate" autowire="byName"/>
<bean id="MQJndiTemplate" class="" primary="false"/>
<bean id="MQJndiTemplate" class="" autowire-candidate="false"/>
</beans>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.