Spring事务配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<!-- 非JNDI数据源配置 -->
<bean id="dataSource"
   class="org.apache.commons.dbcp.BasicDataSource">
   <property name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
   </property>
   <property name="url">
    <value>jdbc:oracle:thin:@localhost:1521:oemrep</value>
   </property>
   <property name="username">
    <value>test</value>
   </property>
   <property name="password">
    <value>test</value>
   </property>
</bean>
<!-- JNDI数据源配置
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
   <property name="jndiName">
    <value>demoDS</value>
   </property>
</bean>-->
<bean id="sessionFactory"
   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="dataSource">
    <ref bean="dataSource" />
   </property>
   <!-- JTA事务管理的配置
   <property name="jtaTransactionManager">
    <ref bean="webLogicServerTransactionManagerFactory"/>
   </property>-->
   <property name="hibernateProperties">
    <props>
     <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
     <prop key="hibernate.show_sql">true</prop>
     <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
     <prop key="hibernate.jdbc.fetch_size">50</prop>
     <prop key="hibernate.jdbc.batch_size">20</prop>
     <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
     <!-- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
     <prop key="hibernate.cache.use_query_cache">true</prop> -->
    </props>
   </property>
   <property name="mappingDirectoryLocations">
    <list>
     <!-- 添加hibernate值对象的路径名 -->
     <value>classpath:/com/htxx/demo/model</value>
    </list>
   </property>
</bean>

<!--hibernate事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sessionFactory" />
   </property>
</bean>

<bean id="transactionManagerJDBC" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource">
    <ref local="dataSource"/>
   </property>
</bean>
<!-- JtaTransactionManager不需要知道 DataSource 和其他特定的资源,因为它将使用容器提供的全局事务管理
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
   <property name="userTransaction"><ref bean="webLogicServerTransactionManagerFactory"/></property>
</bean>-->
<!-- WebLogic服务器事务管理工厂
<bean id="webLogicServerTransactionManagerFactory" class="org.springframework.transaction.jta.WebLogicServerTransactionManagerFactoryBean">
</bean>-->

<!-- 事务拦截器 -->
    <bean id="transactionInterceptor"
        class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager" ref="transactionManager" />
        <property name="transactionAttributeSource"><ref bean="defaultTxAttributes"/></property>
    </bean>

<!-- 事务属性源 -->
<bean id="defaultTxAttributes"
   class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
   <property name="properties">
    <props>
     <prop key="create*">PROPAGATION_REQUIRED</prop>
     <prop key="delete*">PROPAGATION_REQUIRED</prop>
     <prop key="update*">PROPAGATION_REQUIRED</prop>
     <prop key="modify*">PROPAGATION_REQUIRED</prop>
     <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
   </property>
</bean>

<bean id="InvoiceTxAttributes"
   class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
   <property name="properties">
    <props>
     <prop key="create*">PROPAGATION_REQUIRED</prop>
     <prop key="delete*">PROPAGATION_REQUIRED</prop>
     <prop key="update*">PROPAGATION_REQUIRED</prop>
     <prop key="cancel*">PROPAGATION_REQUIRED</prop>
     <prop key="accountIn">PROPAGATION_REQUIRED</prop>
     <prop key="accountOut">PROPAGATION_REQUIRED</prop>
     <prop key="*">PROPAGATION_SUPPORTS</prop>
    </props>
   </property>
</bean>

<!-- 名称匹配的自动代理创建器,所有名字以Bus,Service结尾的bean都将为其创建事务拦截,注释此处就不再被自动事务处理 -->
    <bean name="beanNameAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames">
            <value>*Bus,*Service</value>
        </property>
        <property name="interceptorNames">
            <list>
                <!-- 可以增加其他的拦截器 -->
                <value>transactionInterceptor</value>
            </list>
        </property>
    </bean>
   
    <!-- ehcache缓存处理 -->
<!-- <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
   <property name="configLocation">
     <value>classpath:ehcache.xml</value>
   </property>
</bean>

<bean id="methodCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
   <property name="cacheManager">
     <ref local="cacheManager"/>
   </property>
   <property name="cacheName">
     <value>defaultCache</value>
   </property>
</bean> -->
</beans>

你可能感兴趣的:(Spring事务配置)