zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    英语:真正有效的英语学习心得,把英语当母语学习!(转载)
    《2010年年度总结》
    SQL游标使用
    千万数量级分页存储过程
    关于动态创建DOM元素的问题
    MVC3 “从客户端中检测到有潜在危险的 Request.QueryString或者Request.Form 值”问题解决
    记录Ally项目的点点滴滴(一)总结
    解决session丢失问题
    转载:我的外语学习历程(如何学会十门外语)
    C#经典问题总结一
  • 原文地址:https://www.cnblogs.com/yanglin666/p/10582441.html
Copyright © 2011-2022 走看看