posts - 325,  comments - 25,  trackbacks - 0
          一.
          使用TransactionProxyFactoryBean創(chuàng)建事務(wù)代理(通常事務(wù)代理以Service層為目標(biāo)bean)
          <bean id="personService" class="com.lin.personServiceImpl">
              <property name="personDao" ref="personDao"/>
          </bean>
          //配置hibernate的事務(wù)管理器,使用HibernateTransactionManager類,該類實(shí)現(xiàn)了PlatformTransactionManager接口,針對hibernate 持久化連接的特定實(shí)現(xiàn)
          <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
              <property name="sessionFactory" ref="sessionFactory"/>
          </bean>
          //配置personService bean的事務(wù)代理
          <bean id="personServiceProxy"
                  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
                      //指定事務(wù)管理器
              <property name="transactionManager" ref="transactionManager"/>
                      //指定需要生成代理的日標(biāo)bean
              <property name="persionService" ref="persionService"/>
                      //指定事務(wù)屬性
              <property name="transactionAttributes"
                  <props>
                      <prop key="insert*">PROPAGATION_REQUIRED,-MyCheckedException</prop>
                      <prop key="update*>PROPAGATION_REQUIRED</prop>
                      <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
                  </props>
              </property>


          二.使用自動(dòng)創(chuàng)建代理簡化事務(wù)配置
             使用BeanNameAutoProxyCreator 和DefaultAdvisorAutoProxyCreator創(chuàng)建代理時(shí),并不一定是創(chuàng)建事務(wù)代理,關(guān)鍵在于傳入的攔截器,如果傳入事務(wù)攔截器,將可自動(dòng)生成事務(wù)代理.
          //使用jdbc局部事務(wù)策略
          <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
              <property name="dataSource" ref="dataSource"/>
          </bean>
          //配置目標(biāo)bean1,該目標(biāo)bean將由Bean后處理器自動(dòng)生成代理
          <bean id="testbean1" class="com.lin.Testbean1Impl">
              <property name="dataSource" ref="dataSource"/>
          </bean
          //配置目標(biāo)bean2,該目標(biāo)bean將由Bean后處理器自動(dòng)生成代理
          <bean id="testbean2" class="com.lin.Testbean2Impl">
              <property name="dataSource" ref="dataSource"/>
          </bean
          //配置事務(wù)攔截器bean
          <bean id="transactionInterceptor"
             class="org.springframework.transaction.interceptor.TransactionInterceptor">
                  //事務(wù)攔截器需要注入一個(gè)事務(wù)管理器
                <property name="transactionManager" ref="transactionManager"/>
                 <property name="transactionAttributes">
                      //定義事務(wù)傳播屬性
                      <props>
                              <prop key="insert*">PROPAGATION_REQUIRED</prop>
                              <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                              <prop key="*">PROPAGATION_REQUIRED</prop>
                      </props>
                  </property>
              //定義BeanNameAutoProxyCreator的Bean后處理器
           <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
              <property name="beanNames">
                  <list>
                      <value>testbean1</value>
                      <value>testbean2</value>
                  </list>
                      //此處可以增加其他需要?jiǎng)?chuàng)建事務(wù)代理的bean
              </property>
                  //定義BeanNameAutoProxyCreator所需要的攔截器
               <property name="interceptorNames">
                  <list>
                      <value>transactionInterceptor</value>
                          //此處可以增加其他新的Interceptor
                  </list>
              </property>
           </bean>
              
          posted on 2008-05-18 15:39 長春語林科技 閱讀(778) 評論(0)  編輯  收藏 所屬分類: spring
          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

           

          長春語林科技?xì)g迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 莎车县| 广汉市| 台东县| 漳平市| 永仁县| 富民县| 江山市| 重庆市| 凤城市| 清涧县| 乐清市| 东乡县| 南部县| 临颍县| 台山市| 齐河县| 元阳县| 昌乐县| 奉节县| 龙口市| 延寿县| 大庆市| 中西区| 尚义县| 德昌县| 富裕县| 昌江| 乐平市| 黄龙县| 宁安市| 洛隆县| 图们市| 韩城市| 宁波市| 平远县| 石渠县| 岳普湖县| 新田县| 凤庆县| 乌恰县| 酒泉市|