config配置
project.name=cas-hnist
logback.baseRoot=../logs
#jdbc
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://192.168.0.1;databaseName=td
jdbc.username=sa
jdbc.password=sa
jdbc.initialSize=10
jdbc.maxActive=100
jdbc.maxIdle=20
jdbc.minIdle=1
jdbc.maxWait=60000
jdbc.timeBetweenEvictionRunsMillis=60000
jdbc.minEvictableIdleTimeMillis=300000
#jdbc
jdbc.driverClassName2=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url2=jdbc:sqlserver://192.168.0.1;databaseName=drm
jdbc.username2=sa
jdbc.password2=sa
spring-mybatis.ml配置:
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.meta.hnist.service.impl"/>
<!-- 配置數(shù)據(jù)源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- 初始化連接大小 -->
<property name="initialSize" value="${jdbc.initialSize}"/>
<!-- 連接池最大數(shù)量 -->
<property name="maxActive" value="${jdbc.maxActive}"/>
<!-- 連接池最小空閑 -->
<property name="minIdle" value="${jdbc.minIdle}"/>
<!-- 獲取連接最大等待時間 -->
<property name="maxWait" value="${jdbc.maxWait}"/>
<!-- 配置間隔多久才進行一次檢測肠仪,檢測需要關(guān)閉的空閑連接,單位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
<!-- 配置一個連接在池中最小生存的時間,單位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
<!-- 用來檢測連接是否有效的sql溃肪,要求是一個查詢語句-->
<property name="validationQuery" value="select 1"/>
<!-- 申請連接時執(zhí)行validationQuery檢測連接是否有效,配置為true會降低性能 -->
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
</bean>
<!-- 配置數(shù)據(jù)源 -->
<bean id="dataSource_first" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName2}"/>
<property name="url" value="${jdbc.url2}"/>
<property name="username" value="${jdbc.username2}"/>
<property name="password" value="${jdbc.password2}"/>
<!-- 初始化連接大小 -->
<property name="initialSize" value="${jdbc.initialSize}"/>
<!-- 連接池最大數(shù)量 -->
<property name="maxActive" value="${jdbc.maxActive}"/>
<!-- 連接池最小空閑 -->
<property name="minIdle" value="${jdbc.minIdle}"/>
<!-- 獲取連接最大等待時間 -->
<property name="maxWait" value="${jdbc.maxWait}"/>
<!-- 配置間隔多久才進行一次檢測渗磅,檢測需要關(guān)閉的空閑連接聊替,單位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
<!-- 配置一個連接在池中最小生存的時間,單位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
<!-- 用來檢測連接是否有效的sql寿桨,要求是一個查詢語句-->
<property name="validationQuery" value="select 1"/>
<!-- 申請連接時執(zhí)行validationQuery檢測連接是否有效,配置為true會降低性能 -->
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
</bean>
<!-- Spring整合mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 自動掃描entity目錄, 省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations" value="classpath:mybatis-mappers/*.xml"/>
</bean>
<!--Spring整合mybatis2-->
<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource_first"/>
<!-- 自動掃描entity目錄, 省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations" value="classpath:student-mybatis-mappers/*.xml"/>
</bean>
<!-- MyBatis 動態(tài)掃描 -->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.meta.hnist.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!-- MyBatis 動態(tài)掃描2 -->
<bean id="mapperScannerConfigurer2" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.meta.student.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory2"/>
</bean>
<!-- 配置事務(wù)管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置事務(wù)管理器 -->
<bean id="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource_first"/>
</bean>
<!-- 攔截器方式配置事物 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="edit*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="remove*" propagation="REQUIRED"/>
<tx:method name="evaluate*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS"/>
<tx:method name="query*" propagation="SUPPORTS"/>
<tx:method name="find*" propagation="SUPPORTS"/>
<tx:method name="*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<!-- 攔截器方式配置事物 -->
<tx:advice id="transactionAdvice2" transaction-manager="transactionManager2">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="edit*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="remove*" propagation="REQUIRED"/>
<tx:method name="evaluate*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS"/>
<tx:method name="query*" propagation="SUPPORTS"/>
<tx:method name="find*" propagation="SUPPORTS"/>
<tx:method name="*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<!-- 配置切面 -->
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.meta.hnist.service.impl.*Impl.*(..))"/>
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice"/>
</aop:config>
</beans>
<!-- 配置切面2 -->
<aop:config>
<aop:pointcut id="transactionPointcut2" expression="execution(* com.meta.student.service.impl.*Impl.*(..))"/>
<aop:advisor pointcut-ref="transactionPointcut2" advice-ref="transactionAdvice2"/>
</aop:config>
代碼分開寫