@hunter129

天天学习,好好向上!

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  21 随笔 :: 5 文章 :: 37 评论 :: 0 Trackbacks
上次折腾了半天,终于把延时加载配置好了。可是不配置事务总是觉得怪怪的。so..决定把事务也配置好。虽然是个小项目吧^_^.
<!-- 事务配置 -->
     
<!-- 事务管理器 用于hibernate的事务管理器-->
      
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        
<property name="sessionFactory">
            
<ref bean="sessionFactory"/>
        
</property>
    
</bean>
    
    
<!-- 事务拦截器 用于对拦截的方法开启事务,其中指定了一些只读事务-->
    
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        
<property name="transactionManager" ref="transactionManager"/>
        
<property name="transactionAttributes">
            
<props>
                
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
                
<prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
                
<prop key="*list">PROPAGATION_REQUIRED,readOnly</prop>
                
<prop key="display*">PROPAGATION_REQUIRED,readOnly</prop>
                
<prop key="*display">PROPAGATION_REQUIRED,readOnly</prop>
                
<prop key="*view">PROPAGATION_REQUIRED,readOnly</prop>
                
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                
<prop key="main*">PROPAGATION_REQUIRED,readOnly</prop>
            
</props>
        
</property>
    
</bean>
    
    
<!-- 自动代理,配置使所有service层bean使用事务拦截器 -->
    
<bean 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>

    
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
        
<property name="transactionInterceptor" ref="transactionInterceptor"/>
    
</bean>
    
<!-- 事务配置结束 -->

简单说明一下,其中是用了spring提供的BeanNameAutoProxyCreator这个自动代理服务,自动对名为XXXService的的bean使用使用拦截器开启事务,而在transactionInterceptor则定义了事务的属性,限定了一些只读的事务以提搞效率。
posted on 2008-04-21 19:08 hunter129 阅读(266) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: