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>
<?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>
相关文章推荐
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Spring中属性注入详解
- struts2 spring整合fieldError问题
- spring的jdbctemplate的crud的基类dao
- 读取spring配置文件的方法(spring读取资源文件)
- java实现简单美女拼图游戏
- java基本教程之线程休眠 java多线程教程
- JSP开发中在spring mvc项目中实现登录账号单浏览器登录
- 基于Spring框架的Shiro配置方法
- Spring MVC中上传文件实例
- 实例讲解Java的Spring框架中的AOP实现
- 解析Java中如何获取Spring中配置的bean
- Spring的注解配置与XML配置之间的比较
- java Spring整合Freemarker的详细步骤
- Java 二维码,QR码,J4L-QRCode 的资料整理
- java当中的定时器的4种使用方式
- java中 spring 定时任务 实现代码
- spring mvc实现登录账号单浏览器登录