123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?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"
- 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-3.0.xsd">
- <bean id="dataSourceAdplatform" class="com.alibaba.druid.pool.DruidDataSource"
- init-method="init" destroy-method="close">
- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
- <property name="url" value="${spring.adplatform.jdbcUrl}" />
- <property name="username" value="wx2016_longvideo" />
- <property name="password" value="wx2016_longvideoP@assword1234" />
- <property name="maxActive" value="20" />
- <property name="initialSize" value="1" />
- <property name="maxWait" value="60000" />
- <property name="minIdle" value="3" />
- <property name="connectionProperties" value="config.decrypt=true;clientEncoding=UTF-8" />
- <property name="connectionInitSqls" value="set names utf8mb4;" />
- <property name="filters" value="stat" />
- <property name="timeBetweenEvictionRunsMillis" value="600000" />
- <property name="minEvictableIdleTimeMillis" value="300000" />
- <property name="validationQuery" value="select 1" />
- <property name="testWhileIdle" value="true" />
- <property name="testOnBorrow" value="false" />
- <property name="testOnReturn" value="false" />
- <property name="maxOpenPreparedStatements" value="20" />
- <property name="removeAbandoned" value="true" />
- <property name="removeAbandonedTimeout" value="1800" />
- <property name="logAbandoned" value="true" />
- </bean>
- <bean id="dataSourceOriginal" class="com.alibaba.druid.pool.DruidDataSource"
- init-method="init" destroy-method="close">
- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
- <property name="url" value="${spring.datasource.jdbcUrl}" />
- <property name="username" value="${spring.datasource.username}" />
- <property name="password" value="${spring.datasource.password}" />
- <property name="maxActive" value="20" />
- <property name="initialSize" value="1" />
- <property name="maxWait" value="60000" />
- <property name="minIdle" value="3" />
- <property name="connectionProperties" value="config.decrypt=true;clientEncoding=UTF-8" />
- <property name="connectionInitSqls" value="set names utf8mb4;" />
- <property name="filters" value="stat" />
- <property name="timeBetweenEvictionRunsMillis" value="600000" />
- <property name="minEvictableIdleTimeMillis" value="300000" />
- <property name="validationQuery" value="select 1" />
- <property name="testWhileIdle" value="true" />
- <property name="testOnBorrow" value="false" />
- <property name="testOnReturn" value="false" />
- <property name="maxOpenPreparedStatements" value="20" />
- <property name="removeAbandoned" value="true" />
- <property name="removeAbandonedTimeout" value="1800" />
- <property name="logAbandoned" value="true" />
- </bean>
- <!--动态数据源的配置-->
- <bean id="dynamicDataSource" class=" com.tzld.piaoquan.ad.datasource.DynamicDataSource">
- <property name="targetDataSources">
- <map key-type="java.lang.String">
- <entry key="dataSourceAdplatform" value-ref="dataSourceAdplatform" />
- <entry key="dataSourceOriginal" value-ref="dataSourceOriginal" />
- </map>
- </property>
- </bean>
-
- <bean id="dataSourceChangeAspect" class="com.tzld.piaoquan.ad.datasource.DataSourceAspect">
- <property name="defaultDataSource" value="dataSourceOriginal"></property>
- <property name="targetDataSources">
- <map key-type="java.lang.String">
- <entry key="dataSourceAdplatform" value="dataSourceAdplatform"/>
- <entry key="dataSourceOriginal" value="dataSourceOriginal"/>
- </map>
- </property>
- </bean>
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="dynamicDataSource" />
- <property name="configLocation" value="classpath:mybatis-config.xml" />
- <property name="mapperLocations" value="classpath:mapper/**/*.xml" />
- </bean>
- <!-- 指定Mapper接口所在的包 -->
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
- <property name="basePackage" value="com.tzld.piaoquan.ad.dao.mapper" />
- </bean>
- <!-- 指定事务-->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dynamicDataSource" />
- </bean>
- <!-- 一定要在事务之前切换数据源,不然则会失效-->
- <aop:config>
- <aop:pointcut id="serviceAop" expression="execution(* com.tzld.piaoquan.ad.service..*.*(..))" />
- <aop:aspect ref="dataSourceChangeAspect" order="0">
- <aop:before method="doBefore" pointcut-ref="serviceAop"/>
- <aop:after-returning method="doAfterReturning" pointcut-ref="serviceAop"/>
- </aop:aspect>
- </aop:config>
- <!--配置事务模板对象 编程式事务 模板-->
- <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
- <property name="transactionManager" ref="transactionManager"/>
- </bean>
- </beans>
|