您的位置:首页 > 编程语言 > Java开发

12、Spring-mybatis.xml

2015-06-03 16:47 531 查看

<?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:aop="http://www.springframework.org/schema/aop"

 xmlns:context="http://www.springframework.org/schema/context"

 xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"

 xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd

    http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd

    http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd

    http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd

    http://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.0.xsd">

 <description>Mybatis公共配置文件</description>

    <!--

    <bean id="dataSourceMybatis" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

  <property name="driverClassName" value="${jdbc0.driverClassName}"/>

  <property name="url" value="${jdbc0.url}"/>

  <property name="username" value="${jdbc0.username}"/>

  <property name="password" value="${jdbc0.password}"/>

  <property name="maxActive" value="${jdbc0.maxActive}" />

  <property name="maxIdle" value="${jdbc0.maxIdle}" />

  <property name="maxWait" value="${jdbc0.maxWait}"/>

  <property name="removeAbandoned" value="true"></property>

 </bean>

  -->

 

 <bean id="dataSourceMybatis" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">

     <property name="driverClass" value="${bonecp0.driverClassName}" />

     <property name="jdbcUrl" value="${bonecp0.url}" />

     <property name="username" value="${bonecp0.username}"/>

     <property name="password" value="${bonecp0.password}"/>

     <property name="IdleConnectionTestPeriodInMinutes" value="${bonecp0.idleConnectionTestPeriod}"/>

     <property name="IdleMaxAgeInMinutes" value="${bonecp0.idleMaxAge}"/>

     <property name="maxConnectionsPerPartition" value="${bonecp0.maxConnectionsPerPartition}"/>

     <property name="minConnectionsPerPartition" value="${bonecp0.minConnectionsPerPartition}"/>

     <property name="partitionCount" value="${bonecp0.partitionCount}"/>

     <property name="acquireIncrement" value="${bonecp0.acquireIncrement}"/>

    <property name="poolAvailabilityThreshold" value="${bonecp0.poolAvailabilityThreshold}"></property>

    <property name="ConnectionTimeoutInMs" value="${bonecp0.connectionTimeout}"></property>

  </bean>

 

 

 

    <bean id="vendorProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">

     <property name="properties">

       <props>

         <prop key="Oracle">oracle</prop>

         <prop key="MySQL">mysql</prop>

         <prop key="SQL Server">sqlserver</prop>

         <prop key="DB2">db2</prop>

       </props>

     </property>

   </bean>

   <bean id="databaseIdProvider" class="org.apache.ibatis.mapping.VendorDatabaseIdProvider">

      <property name="properties" ref="vendorProperties"/>

   </bean>

 

 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

  <property name="dataSource" ref="dataSourceMybatis" />

  <!-- 切换数据库时在Mapper.xml的SQL语句上加databaseId="xxx" -->

  <property name="databaseIdProvider" ref="databaseIdProvider" />

  <property name="mapperLocations" >

   <list>

    <value>classpath*:avicit/**/dao/*Mapper.xml</value>

   </list>

  </property>

  <!-- dialect可选值为oracle,mysql,hsqldb,postgresql-->

  <!-- 根据不同的方言采用不同得分也操作 -->

  <property name="plugins">

      <array>

        <bean class="com.demo.core.mybatis.pagehelper.PageHelper">

          <property name="properties">

            <value>

              dialect=oracle

              offsetAsPageNum=true

              rowBoundsWithCount=true

              pageSizeZero=true

              reasonable=true

            </value>

          </property>

        </bean>

      </array>

    </property>

 </bean>

 <!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口-->

 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

  <property name="basePackage" value="avicit" />

  <property name="annotationClass" value="com.demo.core.mybatis.MyBatisRepository"/>

 </bean>

 

 <bean id="transactionManagerMybatis"

  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

  <property name="dataSource" ref="dataSourceMybatis" />

 </bean>

 

  <tx:annotation-driven transaction-manager="transactionManagerMybatis" />

 

 <!-- 以AspectJ方式 定义 AOP 用于事务拦截 -->

 <aop:config proxy-target-class="true">

  <aop:advisor pointcut="execution(* avicit.*.service.*Service*.*(..))" advice-ref="txAdviceMybatis" />

 </aop:config>

 

 <!-- 基本事务定义,使用transactionManagerMybatis作事务管理 -->

 <tx:advice id="txAdviceMybatis" transaction-manager="transactionManagerMybatis">

  <tx:attributes>

   <tx:method name="insert*" propagation="REQUIRED" /> 

   <tx:method name="add*" propagation="REQUIRED" /> 

   <tx:method name="create*" propagation="REQUIRED" />

   <tx:method name="delete*" propagation="REQUIRED" />

   <tx:method name="update*" propagation="REQUIRED" />

   <tx:method name="modify*" propagation="REQUIRED" />

   <tx:method name="save*" propagation="REQUIRED" />

   <tx:method name="do*" propagation="REQUIRED" />

   <tx:method name="before*" propagation="REQUIRED" />

   <tx:method name="after*" propagation="REQUIRED" />

   <tx:method name="find*" propagation="SUPPORTS" read-only="true" />

   <tx:method name="search*" propagation="SUPPORTS" read-only="true" />

   <tx:method name="query*" propagation="SUPPORTS" read-only="true" />

   <tx:method name="load*" propagation="REQUIRED" read-only="true" /> 

   <tx:method name="get*" propagation="SUPPORTS" />

   <tx:method name="*" propagation="SUPPORTS"/>

  </tx:attributes>

 </tx:advice>

</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Spring