Spring 配置之 PropertyPlaceholderConfigurer

<!-- ============= GENERAL DEFINITIONS ============= -->

<!-- Configurer that replaces ${...} placeholders with values from a properties file -->

<!-- (in this case, JDBC-related settings for the dataSource definition below) -->

<bean id="propertyConfigurer"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="location">

<value>classpath:spring/jdbc-oracle.properties</value>

</property>

</bean>

<!--PropertyPlaceholderConfigurer

A property resource configurer that resolves placeholders in bean property values of context definitions. It pulls values from a properties file into bean definitions

->

<!-- ============== RESOURCE DEFINITIONS ========= -->

<!-- Local DataSource that works in any environment -->

<bean id="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName">

<value>${jdbc.driverClassName}</value>

</property>

<property name="url">

<value>${jdbc.url}</value>

</property>

<property name="username">

<value>${jdbc.username}</value>

</property>

<property name="password">

<value>${jdbc.password}</value>

</property>

</bean>

<!--DriverManagerDataSource

Simple implementation of the standard JDBC DataSource interface, configuring the plain old JDBC DriverManager via bean properties, and returning a new Connection from every getConnection call. 

NOTE: This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call

-->

   <!-- Spring iBatis SqlMapClient -->

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

        <property name="configLocation" value="classpath:ibatis/sql-map-config.xml" />

         <property name="dataSource" ref="dataSource"></property>

    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource"></property>

    </bean>

    <bean id="transactionIterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">

     <property name="transactionManager" ref="transactionManager"></property>

     <property name="transactionAttributes">

      <props>

       <prop key="insert*">PROPAGATION_REQUIRED</prop>

       <prop key="add*">PROPAGATION_REQUIRED</prop>

       <prop key="find*,get*">PROPAGATION_REQUIRED,readOnly</prop>

       <prop key="*">PROPAGATION_REQUIRED</prop>

      </props>

     </property>

    </bean>

    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

     <property name="beanNames">

      <list>

       <value>*Service</value>

      </list>

     </property>

     <property name="interceptorNames">

      <list>

       <value>transactionIterceptor</value>

      </list>

     </property>

    </bean>

</beans>

猜你喜欢

转载自mikzhang.iteye.com/blog/1173465