spring事务配置

<!-- 构建HibernateTransactionManager用于获得session,管理事务 -->
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sessionFactory"/>
   </property>
 </bean>
 <!-- 构建TransactionInterceptor,确定给那些方法添加什么事务 -->
 <bean id="interceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
   <property name="transactionManager">
    <ref bean="transactionManager"/>
   </property>
   <property name="transactionAttributes">
    <props>
     <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
   </property>
 </bean>
 <!-- 自动生成代理,将拦截器上的事务添加到指定的类上 -->
 <bean id="auto" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
   <!-- 给哪些对象添加代理  -->
   <property name="beanNames">
    <list>
     <value>*Ser</value>
    </list>
   </property>
   <!-- 给代理添加什么通知(事务事务处理,日志等) -->  
   <property name="interceptorNames">
    <list>
     <idref local="interceptor"/>
    </list>
   </property>
 </bean>
 给所有在spring配置文件中配置的所有bean的id以"Ser"结尾的添加事务。

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