隨筆-153  評論-235  文章-19  trackbacks-0
              數據源:
               <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
                   
          <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
                   
          <property name="url" value="jdbc:mysql://localhost:3306/study"></property>
                   
          <property name="username" value="root"></property>
                   
          <property name="password" value=""></property>
               
          </bean>

              事務管理者:
              <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                  
          <property name="dataSource" ref="dataSource"></property>
              
          </bean>

              被管理的對象:
          <bean id="myBusinessObjectTarget" class="mybusiness.MyBusinessObject"></bean>

              事務性代理對象:
              <bean id="myBusinessObject" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
                  
          <property name="transactionManager" ref="transactionManager"></property>
                  
          <property name="target" ref="myBusinessObjectTarget"></property>
                  
          <property name="transactionAttributes">
                      
          <props>
                          
          <prop key="myBusinessMethod">
                              PROPAGATION_REQUIRED,-MyCheckedException
                          
          </prop>
                      
          </props>
                  
          </property>
              
          </bean>
          說明:-MyCheckedException表示拋出此導常時回滾,+MyCheckedException表示拋出此導常時提交。

              MyBusinessObject:
          package mybusiness;

          /**
           * 
           * 2007-8-20 上午11:26:28
           * 
          @author chenlb
           
          */
          public class MyBusinessObject {

              
          public void myBusinessMethod() throws MyCheckedException {
                  
          // do some resource access
                  
          // return some result object or throw MycheckedException
              }
          }


          聲明式事務的其中一種形式。^_^
          posted on 2007-08-20 11:39 流浪汗 閱讀(583) 評論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 揭东县| 凤山市| 新干县| 大姚县| 连州市| 明光市| 阿尔山市| 华坪县| 永济市| 莆田市| 忻城县| 宝坻区| 辽中县| 邵东县| 轮台县| 阿瓦提县| 保定市| 柳林县| 呼玛县| 新民市| 尚义县| 榆中县| 陇南市| 云龙县| 六盘水市| 射洪县| 于都县| 汽车| 廊坊市| 柳林县| 西吉县| 仁布县| 额尔古纳市| 广东省| 河北省| 嘉兴市| 淅川县| 民乐县| 中牟县| 柳江县| 托里县|