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

  • 相关阅读:
    记录cacti时间筛选bug的解决办法
    mysql开启远程访问权限
    Mysql 5.7.32 安装cacti-0.8.8h出错
    记录Apache无法解析PHP代码解决方法
    zabbix5.0安装问题:Time zone for PHP is not set
    数据库以及数据表的创建
    小程序框架wepy
    通用的代码总结
    html网页什么样的字体最好看,css设置各种中文字体样式代码
    vue中使用BetterScroll(网上)
  • 原文地址:https://www.cnblogs.com/SkyeAngel/p/8306763.html
Copyright © 2011-2022 走看看