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>

  • 相关阅读:
    session中删除数组中的某一个值
    Windows 查看端口占用进程并关闭
    Debian 9 / Debian 10 / Ubuntu 18.04 / Ubuntu 18.10快速开启BBR加速 或 关闭BBR加速
    在ASP.NET Web API 2中使用Owin OAuth 刷新令牌(示例代码)
    在ASP.NET Web API 2中使用Owin基于Token令牌的身份验证
    Web API 2 的操作结果
    WebApi接口安全性 接口权限调用、参数防篡改防止恶意调用
    关于EF中使用Migrations的一些小提示
    Entity Framework 6 多对多增改操作指南
    用MVC5+EF6+WebApi 做一个考试功能(六) 仓储模式 打造EF通用仓储类
  • 原文地址:https://www.cnblogs.com/yanglin666/p/10582441.html
Copyright © 2011-2022 走看看