`

Spring Hibernate使用TransactionInterceptor声明式事务配置

阅读更多

<!-- 事务管理器 -->
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
     <property name="sessionFactory">
         <ref bean="sessionFactory"/>
     </property>
 </bean>
 <!-- 事务拦截器,激活事务管理器所必须的bean -->
 <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> 
        <property name="transactionManager"> 
            <ref bean="transactionManager" /> 
        </property>  
        <!-- 配置事务属性 --> 
        <property name="transactionAttributes"> 
           <props> 
              <prop key="delete*">PROPAGATION_REQUIRED</prop> 
              <prop key="add*">PROPAGATION_REQUIRED</prop> 
              <prop key="update*">PROPAGATION_REQUIRED</prop> 
              <prop key="save*">PROPAGATION_REQUIRED</prop> 
              <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> 
          </props> 
       </property> 
     </bean> 
     <!-- 定义事务处理代理bean,他需要两个属性,一个是指定需要代理的bean,另一个是代理bean所需的事务拦截器 -->
     <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> 
        <property name="beanNames"> 
           <list> 
              <value>tempService</value> 
           </list> 
        </property> 
        <property name="interceptorNames"> 
           <list> 
              <value>transactionInterceptor</value> 
           </list> 
        </property> 
     </bean>
    <!-- 业务逻辑层 -->
 <bean id="tempService"
  class="com.cj.transaction.service.TempService" abstract="false"
  lazy-init="default" autowire="default" dependency-check="default">
  <property name="userDAO">
   <ref bean="userDAO" />
  </property>
  <property name="deptDAO">
   <ref bean="deptDAO" />
  </property>
 </bean>
 <bean id="userDAO" class="com.cj.transaction.hibernate.UserDAO">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>
 <bean id="deptDAO" class="com.cj.transaction.hibernate.DeptDAO">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>

如果模块过多话,可以考虑用自动创建事务代理的方式
    <!-- 自动代理 --> 
    <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> 
       <property name="beanNames"> 
          <list> 
             <value>*Service</value> 
          </list> 
       </property> 
       <property name="interceptorNames"> 
          <list> 
             <value>transactionInterceptor</value> 
          </list> 
       </property> 
    </bean>

 

分享到:
评论

相关推荐

    Spring_Hibernate使用TransactionInterceptor声明式事务配置.doc

    Spring_Hibernate使用TransactionInterceptor声明式事务配置.doc

    Spring Hibernate事务实例

    Spring+Hibernate 使用TransactionInterceptor声明式事务配置

    Spring + Hibernate + Struts 事务配置小例子(带提示框等小技巧)

    前几天搞 Spring + Hibernate + Struts 事务配置 ,网上找了好多资料,不过好无语,大多都是 Ctrl + V,浪费俺的宝贵时间 现在我总结配出一套,给大家参考参考,可能有不足,请大家多多交流。 附:内有弹出...

    Spring

    --这里是自定义的拦截器的实现,在Spring的ProxyFactoryBean类中必须 指定interceptorNames的值 --&gt; &lt;bean id="transactionInterceptor" class="org.nitpro.aop.TransactionInterceptor"&gt; &lt;!--bizImpl为我们自己的...

    org.springframework.transaction-3.1.2.RELEASE.zip

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionInterceptor#0': Error setting property values; nested ...

    Spring笔记说明文件

    TransactionInterceptor;保存了事务属性信息,事务管理器; 他是一个 MethodInterceptor; 在目标方法执行的时候; 执行拦截器链; 事务拦截器: 1)、先获取事务相关的属性 2)、再获取...

    SPRING API 2.0.CHM

    HibernateInterceptor HibernateJdbcException HibernateJdbcException HibernateJpaDialect HibernateJpaVendorAdapter HibernateObjectRetrievalFailureException HibernateObjectRetrievalFailureException...

    Myeclipse6.0中SSH框架搭建

    class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;!-- 其它Bean定义在此 --&gt; &lt;!-- 定义拦截器 --&gt; ...

    COS——R.log

    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed...

Global site tag (gtag.js) - Google Analytics