spring util标签

   util 在spring2.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:c="http://www.springframework.org/schema/c" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/util
           http://www.springframework.org/schema/util/spring-util.xsd">


</beans>

 

  • constant :将指定类的静态Field配置成一个Bean实例。可以替换org.springframework.beans.factory.config.FieldRetrievingFactoryBean
	<!-- 替换上一节写法 -->
	<util:constant id="length" static-field="i.test.Test3.MAX_LENGTH" />
  • property-path:将类的属性(有getter方法)通过配置成一个Bean实例。可以替换org.springframework.beans.factory.config.PropertyPathFactoryBean
    	<bean id="t3" class="i.test.Test3" />
    	<!-- 替换上一节写法 -->
    	<util:property-path id="name" path="t3.t1.name" />
     
  • list:定义一个List Bean

      befor...

<!-- creates a java.util.List instance with values loaded from the supplied 'sourceList' -->
<bean id="emails" class="org.springframework.beans.factory.config.ListFactoryBean">
  <property name="sourceList">
      <list>
        <value>[email protected]</value>
        <value>[email protected]</value>
        <value>[email protected]</value>
        <value>[email protected]</value>
      </list>
  </property>
</bean>

    after...

<!-- creates a java.util.List instance with the supplied values -->
<util:list id="emails">
    <value>[email protected]</value>
    <value>[email protected]</value>
    <value>[email protected]</value>
    <value>[email protected]</value>
</util:list>

    or

<util:list id="emails" list-class="java.util.LinkedList">
    <value>[email protected]</value>
    <value>[email protected]</value>
    <value>[email protected]</value>
    <value>d'[email protected]</value>
</util:list>
  • map:定义一个Map Bean

          befor...

    <!-- creates a java.util.Map instance with values loaded from the supplied 'sourceMap' -->
    <bean id="emails" class="org.springframework.beans.factory.config.MapFactoryBean">
      <property name="sourceMap">
          <map>
            <entry key="pechorin" value="[email protected]"/>
            <entry key="raskolnikov" value="[email protected]"/>
            <entry key="stavrogin" value="[email protected]"/>
            <entry key="porfiry" value="[email protected]"/>
          </map>
      </property>
    </bean>
    after...
    <!-- creates a java.util.Map instance with the supplied key-value pairs -->
    <util:map id="emails">
        <entry key="pechorin" value="[email protected]"/>
        <entry key="raskolnikov" value="[email protected]"/>
        <entry key="stavrogin" value="[email protected]"/>
        <entry key="porfiry" value="[email protected]"/>
    </util:map>
     or
    <util:map id="emails" map-class="java.util.TreeMap">
        <entry key="pechorin" value="[email protected]"/>
        <entry key="raskolnikov" value="[email protected]"/>
        <entry key="stavrogin" value="[email protected]"/>
        <entry key="porfiry" value="[email protected]"/>
    </util:map>
     
  • properties : 用户加载资源文件,生成一个Properties Bean
    <!-- creates a java.util.Properties instance with values loaded from the supplied location -->
    <bean id="jdbcConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
      <property name="location" value="classpath:com/foo/jdbc-production.properties"/>
    </bean>
     after..
    <!-- creates a java.util.Properties instance with values loaded from the supplied location -->
    <util:properties id="jdbcConfiguration" location="classpath:com/foo/jdbc-production.properties"/>
     
  •  
   util 在spring2.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:c="http://www.springframework.org/schema/c" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/util
           http://www.springframework.org/schema/util/spring-util.xsd">


</beans>
 
  • constant :将指定类的静态Field配置成一个Bean实例。可以替换org.springframework.beans.factory.config.FieldRetrievingFactoryBean

猜你喜欢

转载自flyouwith.iteye.com/blog/2197510