zoukankan      html  css  js  c++  java
  • JavaEE——Spring4--(11)Spring的事务管理(xml文件方式)

    不用再在接口方法中标注解,直接在配置xml文件中写

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    
        <!--扫描包-->
        <context:component-scan base-package="jdbc"></context:component-scan>
    
        <!--导入资源文件-->
        <context:property-placeholder location="classpath:db.properties"/>
    
        <!--配置C3P0数据源-->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="user" value="${jdbc.user}"></property>
            <property name="password" value="${jdbc.password}"></property>
            <property name="driverClass" value="${jdbc.driverClass}"></property>
            <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
    
            <property name="initialPoolSize" value="${jdbc.initPoolSize}"></property>
            <property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
        </bean>
    
        <!--配置Spring的JDBCTemplate-->
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="dataSource"></property>
        </bean>
    
        <!--配置bean-->
        <bean id="bookShopDAO" class="jdbc.transactionManager.BookShopDAOImpl">
            <property name="jdbcTemplate" ref="jdbcTemplate"></property>
        </bean>
    
        <bean id="bookShopService" class="jdbc.transactionManager.BookShopServiceImpl">
            <property name="bookShopDAO" ref="bookShopDAO"></property>
        </bean>
    
        <!--1.配置事务管理器-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"></property>
        </bean>
    
        <!--2.配置事务属性-->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="*"/>
            </tx:attributes>
        </tx:advice>
    
        <!--3.配置事务切入点,以及把事务切入点与事务属性关联起来-->
        <aop:config>
            <aop:pointcut id="txPointCut" expression="execution(* jdbc.transactionManager.BookShopService.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
        </aop:config>
    </beans>
    

      

     

     关于xml配置的事务管理可参考https://blog.csdn.net/Evankaka/article/details/45478007

  • 相关阅读:
    Silverlight4 打印 生成文件过大解决
    清理 Visual Studio 工具箱 的冗杂控件(第三方控件卸载不完全)
    SQL2005SP4生成数据库脚本视图依赖顺序错误问题
    SQL Server 2005 企业版没有 Management Studio管理工具
    Excel Reader 轻量级
    开发托管ActiveX或第三方程序托管插件时调试问题解决方法
    Entity Framework 从数据库生成模型丢失数据库文档不完美解决方案
    今天写了个很蛋疼的sql语句
    WinForm 内嵌 Office 文档 解决方案测试(非DSOFRAME 纯C#代码,网上独一份)
    生产者、消费者问题之闹钟
  • 原文地址:https://www.cnblogs.com/SkyeAngel/p/8306763.html
Copyright © 2011-2022 走看看