MDA/MDD/TDD/DDD/DDDDDDD
          posts - 536, comments - 111, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          aop配置事務

          Posted on 2009-12-24 22:04 leekiang 閱讀(296) 評論(0)  編輯  收藏 所屬分類: spring
          事務直接配到DAO上
          <bean id="transactionManager"
          ?? ??? ?class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          ?? ??? ?<property name="dataSource" ref="dataSource" />
          ?? ?</bean>

          ?? ?<bean id="baseTxProxy"
          ?? ??? ?class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
          ?? ??? ?lazy-init="true" abstract="true">
          ?? ??? ?<property name="transactionManager">
          ?? ??? ??? ?<ref bean="transactionManager" />
          ?? ??? ?</property>
          ?? ??? ?<property name="transactionAttributes">
          ?? ??? ??? ?<props>
          ?? ??? ??? ??? ?<prop key="update*">PROPAGATION_REQUIRED</prop>
          ?? ??? ??? ?</props>
          ?? ??? ?</property>
          ?? ?</bean>

          ?? ?<bean id="studentDaoProxy" parent="baseTxProxy">
          ?? ??? ?<property name="target">
          ?? ??? ??? ?<ref bean="studentDao" />
          ?? ??? ?</property>
          ?? ?</bean>

          ?? ?<bean id="studentDao" class="com.dao.StudentDaoImpl">
          ?? ??? ?<property name="dataSource" ref="dataSource" />
          ?? ?</bean>
          ?? ?
          ?? ?StudentDao st = (StudentDao) context.getBean("studentDaoProxy");
          ?? ?
          ?? ?兩個bean也可以合并為
          ?? ?<bean id="studentDao" parent="baseTxProxy">
          ?? ??? ?<property name="target">
          ?? ??? ??? ?<bean class="com.dao.StudentDaoImpl">
          ?? ??? ??? ??? ?<property name="dataSource" ref="dataSource" />
          ?? ??? ??? ??? ?<property name="kpiDao" ref="kpiDao" />
          ?? ??? ??? ?</bean>
          ?? ??? ?</property>
          ?? ?</bean>
          ?? ?StudentDao st = (StudentDao) context.getBean("studentDao");
          ?? ?上述這種方式必須使用接口,為什么。
          ?? ?
          ?? ?
          ?? ?第二種同樣必須用接口。配置起來比第一種麻煩
          ?? ??? ?<bean id="transactionManager"
          ?? ??? ?class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          ?? ??? ?<property name="dataSource" ref="dataSource" />
          ?? ?</bean>

          ?? ?<bean id="transactionInterceptor"
          ?? ??? ?class="org.springframework.transaction.interceptor.TransactionInterceptor">
          ?? ??? ?<property name="transactionManager" ref="transactionManager" />
          ?? ??? ?<property name="transactionAttributes">
          ?? ??? ??? ?<props>
          ?? ??? ??? ??? ?<prop key="update*">PROPAGATION_REQUIRED</prop>
          ?? ??? ??? ?</props>
          ?? ??? ?</property>
          ?? ?</bean>
          ?? ?<bean id="studentDaoProxy"
          ?? ??? ?class="org.springframework.aop.framework.ProxyFactoryBean">
          ?? ??? ?<property name="target" ref="studentDao" />
          ?? ??? ?<property name="interceptorNames">
          ?? ??? ??? ?<list>
          ?? ??? ??? ??? ?<value>transactionInterceptor</value>
          ?? ??? ??? ?</list>
          ?? ??? ?</property>
          ?? ?</bean>
          ?? ?
          ?? ?<bean id="studentDao" class="com.dao.StudentDaoImpl">
          ?? ??? ?<property name="dataSource" ref="dataSource" />
          ?? ?</bean>
          ?? ?ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
          ?? ?StudentDao st = (StudentDao) context.getBean("studentDaoProxy");
          ?? ?
          ?? ?如果使用的都是接口,那么就不需要用cglib-nodep-2.1_3.jar
          ?? ?如果service調dao沒有用到接口,那么必須用cglib-nodep-2.1_3.jar


          事務策略: 了解事務陷阱 http://www.ibm.com/developerworks/cn/java/j-ts1.html 事務策略: 高并發策略 http://www.ibm.com/developerworks/cn/java/j-ts5/index.html 這是一個系列.

          http://beet.sourceforge.net
          Beet records user behavior and performance data for your Spring-based Java application.? It can thus help you to analyze usage patterns and research production performance issues.
          主站蜘蛛池模板: 屯留县| 宣恩县| 阿鲁科尔沁旗| 砚山县| 保亭| 清远市| 泗阳县| 昭通市| 睢宁县| 原阳县| 开远市| 遵化市| 政和县| 界首市| 惠来县| 江川县| 剑川县| 迭部县| 庆阳市| 贵定县| 拉孜县| 霞浦县| 元江| 特克斯县| 宜春市| 吉林省| 岑巩县| 海盐县| 改则县| 永定县| 象州县| 镇江市| 峨眉山市| 荥阳市| 榕江县| 景宁| 黑龙江省| 通城县| 桂东县| 罗定市| 青川县|