@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 閱讀(278) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 台北县| 鸡西市| 灵山县| 镇巴县| 盐亭县| 油尖旺区| 福鼎市| 阿拉善右旗| 称多县| 双辽市| 桃江县| 新安县| 栖霞市| 福州市| 黑水县| 醴陵市| 安塞县| 凤翔县| 卢龙县| 吴堡县| 山东省| 夏邑县| 博白县| 祁门县| 沈阳市| 安国市| 平昌县| 鄂尔多斯市| SHOW| 丘北县| 海门市| 武威市| 分宜县| 天柱县| 葵青区| 宁城县| 鹤壁市| 栖霞市| 日照市| 平舆县| 越西县|