zoukankan      html  css  js  c++  java
  • Spring初学之spring的事务管理xml

    所有的java类都是用的上一篇文章:Spring初学之spring的事务管理

    不同的是,这时xml配置事务,所以就要把java类中的那些关于spring的注解都删掉,然后在xml中配置,ApplicationContext.xml如下:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xmlns:tx="http://www.springframework.org/schema/tx"
     5     xmlns:context="http://www.springframework.org/schema/context"
     6     xmlns:aop="http://www.springframework.org/schema/aop"
     7     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
     8         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
     9         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    10         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    11 
    12     <!-- 导入资源文件 -->
    13     <context:property-placeholder location="classpath:jdbc.properties"/>
    14     
    15     <!-- 配置c3p0数据源 -->
    16     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    17         <property name="user" value="${user}"></property>
    18         <property name="password" value="${password}"></property>
    19         <property name="driverClass" value="${driverClass}"></property>
    20         <property name="jdbcUrl" value="${jdbcUrl}"></property>
    21         
    22         <property name="initialPoolSize" value="${initPoolSize}"></property>
    23         <property name="maxPoolSize" value="${maxPoolSize}"></property>
    24     </bean>
    25     
    26     <!-- 配置spring 的JdbcTemplate -->
    27     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    28         <property name="dataSource" ref="dataSource"></property>
    29     </bean>
    30     
    31     <bean id="bookShopDao" class="spring.tx.xml.BookShopDaoImp">
    32         <property name="jdbcTemplate" ref="jdbcTemplate"></property>
    33     </bean>
    34     
    35     <bean id="bookShopService" class="spring.tx.xml.BookShopServiceImpl">
    36         <property name="bookShopDao" ref="bookShopDao"></property>
    37     </bean>
    38     
    39     <bean id="cashier" class="spring.tx.xml.CashierImpl">
    40         <property name="bookShopService" ref="bookShopService"></property>
    41     </bean>
    42     
    43     <!-- 配置事务管理器 -->
    44     <bean id="transactionManager" 
    45         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    46             <property name="dataSource" ref="dataSource"></property>
    47     </bean>
    48     
    49     <!-- 配置事务属性 -->
    50     <tx:advice id="txAdvice" transaction-manager="transactionManager">
    51         <tx:attributes>
    52             <tx:method name="*" />
    53         </tx:attributes>
    54     </tx:advice>
    55     
    56     <!-- 配置事务切入点,并把事务切入点与事务属性关联起来 -->
    57     <aop:config>
    58         <aop:pointcut expression="execution(* spring.tx.xml.BookShopService.*(..))" id="txPointcut"/>
    59         
    60         <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
    61     </aop:config>
    62     
    63 </beans>
    applicationContext.xml
  • 相关阅读:
    element-ui 和ivew-ui的table导出export纯前端(可用)
    webstrom 2019 注册码(可用 2019年10月14日08:59:18)
    intellji IDEA 2019版激活码(亲测可用 2019年10月14日08:53:54)
    java开发相关工具安装包分享
    js有关字符串拼接问题
    js增删class的方法
    有关定位问题
    关于网页元素居中常见的两种方法
    有关css编写文字动态下划线
    js获取时间及转化
  • 原文地址:https://www.cnblogs.com/hyyq/p/6705728.html
Copyright © 2011-2022 走看看