AOP 事物连接,记忆连接数据库,连接池

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns="http://www.springframework.org/schema/beans"
 xsi:schemaLocation="http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-4.2.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-4.2.xsd ">
     
    <!--指定读取配置文件 -->
       <context:property-placeholder location="classpath:db.properties"/>
    <!-- 事物核心管理器  依赖连接池 -->
        <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
               <property name="dataSource" ref="dataSource"></property>
        </bean>
    <!-- 事物模板对象  -->
        <bean name="transactionTemplat" class="org.springframework.transaction.support.TransactionTemplate">
              <property name="transactionManager" ref="transactionManager"></property>
         </bean>
   <!-- p配置事物通知  -->
         <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="transfer" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
            </tx:attributes>
         </tx:advice>
       <!-- 配置织入  -->
         <aop:config>
     <!-- 切点表达式 -->
             <aop:pointcut expression="execution(* cn.yanglin.service.*ServiceImp.*(..))" id="txPc"/>
     <!-- 配通知给 切点-->
             <aop:advisor advice-ref="txAdvice" pointcut-ref="txPc"/>
         </aop:config>
  <!--1 将连接池放进spring容器 -->
   <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
       <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
       <property name="driverClass" value="${jdbc.driverClass}"></property>
       <property name="user" value="${jdbc.user}"></property>
       <property name="password" value="${jdbc.password}"></property>
   </bean>
   <!-- 2 将jdbc模板放进连接池 -->
    <bean name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
         <property name="dataSource" ref="dataSource"></property>
   </bean>
   <!-- 3将AccountDaoIml放进连接池 -->
   <bean name="accountDaoImp" class="cn.yanglin.dao.AccountDaoImp">
           <property name="dataSource" ref="dataSource"></property>
   </bean>
   <!-- 4将放进连接池 -->
   <bean name="accountService" class="cn.yanglin.service.AccountServiceImp">
           <property name="ad" ref="accountDaoImp"></property>
   </bean>
</beans>

原文地址:https://www.cnblogs.com/yanglin666/p/10582441.html