bean装配样式大全

9 篇文章 0 订阅
6 篇文章 0 订阅
<?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: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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值