posts - 23, comments - 0, trackbacks - 0, articles - 3
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          作者: beauty9235  鏈接:http://beauty9235.javaeye.com/blog/229654  發(fā)表時(shí)間: 2008年05月23日

          聲明:本文系JavaEye網(wǎng)站發(fā)布的原創(chuàng)博客文章,未經(jīng)作者書(shū)面許可,嚴(yán)禁任何網(wǎng)站轉(zhuǎn)載本文,否則必將追究法律責(zé)任!

          事務(wù)代理標(biāo)準(zhǔn)寫(xiě)法

           

          <!--DAO層接口實(shí)現(xiàn)  -->
          <bean id="userDAO" class="net.test.dao.UserDAO">
                 
          <property name="sessionFactory">
                        
          <ref local="sessionFactory" />
                 
          </property>
          </bean>
           
          <!--業(yè)務(wù)層接口實(shí)現(xiàn),把DAO注入到Service里面 --> 
          <bean name="userServiceTarget" class="net.test.service.UserService">
                 
          <property name="userDAO">
                        
          <ref bean="userDAO" />
                 
          </property>
          </bean>
          <!--spring代理業(yè)務(wù)層的事務(wù)管理 -->
          <bean id="userServiceProxy"  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
                 
          <property name="transactionManager">
                        
          <ref local="transactionManager" />
                 
          </property>
                 
          <property name="transactionAttributes">
                        
          <props>
                              
          <prop key="insert*">PROPAGATION_REQUIRED</prop>
                              
          <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                        
          </props>
                 
          </property>
                 
          <property name="target">
                        
          <ref bean="userServiceTarget" />
                 
          </property>
          </bean>

          事務(wù)代理簡(jiǎn)寫(xiě)法

           

          <bean id="baseTxProxy" lazy-init="true"
                  class
          ="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
                  
          <property name="transactionManager">
                      
          <ref bean="transactionManager" />
                  
          </property>
                  
          <property name="transactionAttributes">
                      
          <props>
                          
          <prop key="insert*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                      
          </props>
                  
          </property>
              
          </bean>
              
          <bean id="userDAO" class="net.test.dao.UserDAO">
                  
          <property name="sessionFactory">
                      
          <ref local="sessionFactory" />
                  
          </property>
              
          </bean>
              
          <bean id="userServiceProxy" parent="baseTxProxy">
                  
          <property name="target">
                      
          <bean class="net.test.service.UserService">
                          
          <property name="userDAO">
                              
          <ref local="userDAO" />
                          
          </property>
                      
          </bean>
                  
          </property>
              
          </bean>

          事務(wù)自動(dòng)化代理寫(xiě)法

           

          <!-- 定義事務(wù)攔截器bean -->
              
          <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
                  
          <property name="transactionManager" ref="transactionManager"/>
                  
          <property name="transactionAttributes">
                      
          <props>
                          
          <prop key="insert*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="update*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="delete*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                          
          <prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
                          
          <prop key="*">PROPAGATION_REQUIRED</prop>
                      
          </props>
                  
          </property>
              
          </bean>
              
          <!--定義BeanNameAutoProxyCreator-->
              
          <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
                  
          <property name="beanNames">
                  
          <!--
                       所有名字以DAO,Service結(jié)尾的bean,
                      將由該"bean后處理器"為其創(chuàng)建事務(wù)代理;
                      實(shí)際上應(yīng)該在業(yè)務(wù)層進(jìn)行事務(wù)管理,
                      這里只是舉一個(gè)簡(jiǎn)單例子 
                      
          -->
                      
          <value>*DAO,*ServiceProxy</value>
                  
          </property>
                  
          <!--下面定義BeanNameAutoProxyCreator所需的事務(wù)攔截器-->
                  
          <property name="interceptorNames">
                      
          <list>
                      
          <!--可以增加其他的攔截器-->
                      
          <value>transactionInterceptor</value>
                      
          </list>
                  
          </property>
              
          </bean>
              
          <bean id="userDAO" class="net.test.dao.UserDAO">
                  
          <property name="sessionFactory">
                      
          <ref local="sessionFactory" />
                  
          </property>
              
          </bean>
              
          <bean id="userServiceProxy" class="net.test.service.UserService">
                  
          <property name="userDAO">
                      
          <ref bean="userDAO" />
                  
          </property>
              
          </bean>

          本文的討論也很精彩,瀏覽討論>>


          JavaEye推薦




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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 元朗区| 阳信县| 玉龙| 南宁市| 鹤壁市| 常山县| 时尚| 托克逊县| 都匀市| 岱山县| 同心县| 阿拉善右旗| 白河县| 河北区| 芮城县| 磐石市| 盱眙县| 庐江县| 金溪县| 句容市| 绥滨县| 文水县| 新源县| 芦山县| 大悟县| 上虞市| 民权县| 长泰县| 本溪市| 于田县| 阳山县| 牡丹江市| 普宁市| 湾仔区| 祁门县| 天峻县| 崇明县| 嵊州市| 英德市| 都匀市| 德令哈市|