您的位置:首页 > 编程语言 > Java开发

Spring事务管理

2014-11-17 22:05 375 查看
一、声明式事务管理步骤:

       1、配置数据源

             <bean id="dataSource"   class="org.springframework.jdbc.datasource.DriverManagerDataSource">

                    <property   name="driverClassName"    value="oracle.jdbc.driver.OracleDriver"></property>

                    <property   name="url"   value="jdbc:oracle:thin:@192.168.10.3:1521:orcl"></property>

                    <property   name="username"   value="yannan"></property>

                    <property   name="password“    value="123456"></property>

             </bean>

      2、配置事务管理对象

              <bean  id="txManager"   class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

                    <property   name="dataSource"   ref="dataSource" />

              </bean>

      3、配置事务策略

                <tx:advice  id="txAdvice"   transaction-manager="txManager">

                        <tx:attributes>

                                 <tx:method  name="get*"   read-only="true" />

                                 <tx:method  name="*" />

                         </tx:attributes>

               </tx:advice>

      4、配置AOP

            <aop:config>

                      <aop:pointcut 
id="busServiceMethods"   expression="execution(*  org.huawei.business.*.*(..))" />

                      <aop:advisor  advice-ref="txAdvice" 
pointcut-ref="busServiceMethods" />

           </aop:config>

                  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息