<?xml version="1.0" encoding="UTF-8"?> <!-- @author ForeignStudent @version 2017/9/20 --> <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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 這裏能夠不用掃描properties配置文件,可是爲了之後能夠把配置文件分開,因此加上,這裏掃描的是同一個 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:applicationContext/spring.properties</value> </list> </property> </bean> <!-- 數據源 --> <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${sql_member_driver}" /> <property name="url" value="${sql_member_url}" /> <property name="username" value="${sql_member_username}" /> <property name="password" value="${sql_member_password}" /> <property name="initialSize" value="${sql_member_initalSize}" /> <property name="maxTotal" value="${sql_member_maxTotal}" /> <property name="maxIdle" value="${sql_member_maxIdle}" /> <property name="minIdle" value="${sql_member_minIdle}" /> <property name="maxWaitMillis" value="${sql_member_maxWaitMillis}" /> </bean> <!-- spring和MyBatis整合 --> <bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations" value="classpath*:com/conferencerooms/mapperXml/*Mapper.xml" /> <property name="typeAliasesPackage" value="com.conferencerooms.entity" /> <property name="plugins"> <array> <!-- 分頁插件配置 --> <bean id="paginationInterceptor" class="com.baomidou.mybatisplus.plugins.PaginationInterceptor"> <property name="dialectType" value="mysql" /> </bean> </array> </property> <!-- 全局配置注入 --> <property name="globalConfig" ref="globalConfig" /> </bean> <bean id="globalConfig" class="com.baomidou.mybatisplus.entity.GlobalConfiguration"> <!-- AUTO->`0`("數據庫ID自增") INPUT->`1`(用戶輸入ID") ID_WORKER->`2`("全局惟一ID") UUID->`3`("全局惟一ID") --> <property name="idType" value="3" /> <!-- MYSQL->`mysql` ORACLE->`oracle` DB2->`db2` H2->`h2` HSQL->`hsql` SQLITE->`sqlite` POSTGRE->`postgresql` SQLSERVER2005->`sqlserver2005` SQLSERVER->`sqlserver` --> <!-- Oracle須要添加該項 --> <!-- <property name="dbType" value="oracle" /> --> <!-- 全局表爲下劃線命名設置 true --> <property name="dbColumnUnderline" value="true" /> </bean> <!-- MyBatis 動態實現 --> <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 對Dao 接口動態實現,須要知道接口在哪 --> <property name="basePackage" value="com.conferencerooms.mapper" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean> <!-- 事務管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 事務註解 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> <!-- 事務管理 屬性 --> <tx:advice id="transactionAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="select*" propagation="REQUIRED" read-only="true" /> <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <!-- 配置切面 --> <aop:config expose-proxy="true" proxy-target-class="true"> <aop:advisor advice-ref="transactionAdvice" pointcut="execution(* com.conferencerooms.service..*.*(..))" /> </aop:config> </beans>