@hunter129

          天天學(xué)習(xí),好好向上!

             :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            21 隨筆 :: 5 文章 :: 37 評論 :: 0 Trackbacks
          上次折騰了半天,終于把延時(shí)加載配置好了。可是不配置事務(wù)總是覺得怪怪的。so..決定把事務(wù)也配置好。雖然是個(gè)小項(xiàng)目吧^_^.
          <!-- 事務(wù)配置 -->
               
          <!-- 事務(wù)管理器 用于hibernate的事務(wù)管理器-->
                
          <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                  
          <property name="sessionFactory">
                      
          <ref bean="sessionFactory"/>
                  
          </property>
              
          </bean>
              
              
          <!-- 事務(wù)攔截器 用于對攔截的方法開啟事務(wù),其中指定了一些只讀事務(wù)-->
              
          <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>
              
              
          <!-- 自動(dòng)代理,配置使所有service層bean使用事務(wù)攔截器 -->
              
          <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>
              
          <!-- 事務(wù)配置結(jié)束 -->

          簡單說明一下,其中是用了spring提供的BeanNameAutoProxyCreator這個(gè)自動(dòng)代理服務(wù),自動(dòng)對名為XXXService的的bean使用使用攔截器開啟事務(wù),而在transactionInterceptor則定義了事務(wù)的屬性,限定了一些只讀的事務(wù)以提搞效率。
          posted on 2008-04-21 19:08 hunter129 閱讀(276) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 临江市| 新竹市| 诏安县| 偃师市| 鹤山市| 屏东县| 将乐县| 元江| 阿瓦提县| 长海县| 沁水县| 巩留县| 稻城县| 晋江市| 塘沽区| 行唐县| 阳原县| 察隅县| 靖安县| 曲阳县| 信阳市| 韶关市| 兴隆县| 苏尼特左旗| 桦甸市| 自贡市| 灌南县| 资中县| 易门县| 林口县| 嘉鱼县| 宾川县| 日土县| 江津市| 吐鲁番市| 和平区| 根河市| 阜城县| 文山县| 衡东县| 方山县|