applicationContext中事物的使用

来源:互联网 发布:长岛的雪 内涵 知乎 编辑:程序博客网 时间:2024/05/19 11:48

    最近项目中用到了事务,所以把项目中用到的写出来:

 

 

 <!-- 事务的定义 -->
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>
 <!-- 定义具体到方法的事务处理 -->
 <bean id="txAttributeSource"
  class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
  <property name="properties">
   <props>
    <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="update*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="del*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property>
 </bean>
 <bean id="txInterceptor"
  class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager" ref="transactionManager" />
  <property name="transactionAttributeSource"
   ref="txAttributeSource" />
 </bean>

 <!-- 根据名称注入事务 -->
 <bean id="autoProxyCreator"
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="interceptorNames">
   <list>
    <idref local="txInterceptor" />
   </list>
  </property>
  <property name="beanNames">
   <!-- 将事务注入到相应的业务处理类中去!(将你们每个模块的业务写入 -->
   <list>
        <idref bean="logService"/> 
        <idref bean="uploadAudioService"/>   
   </list>
  </property>
 </bean>

原创粉丝点击