主数据库的配置
package com.lantu.platform.admin.baseConfig;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.aspectj.lang.annotation.Aspect;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import com.lantu.platform.admin.common.interceptor.SyncInterceptor;
import com.lantu.platform.admin.common.interceptor.paginate.PaginationStatementHandlerInterceptor;
import tk.mybatis.spring.annotation.MapperScan;
@Aspect
@Configuration
@PropertySource(value = {
"classpath:database.properties"})
@MapperScan(basePackages = {
"com.lantu.platform.admin.mapper.masterMapper"},
sqlSessionFactoryRef = "masterSqlSessionFactory")
public class DBMasterConfig {
private static final String AOP_POINTCUT_EXPRESSION = "execution(* com.lantu.platform.admin.*.service.impl..*.*(..))";
@Bean(name="masterDataSource")
@Primary
@ConfigurationProperties(prefix = "spring.datasource.master")
public DataSource setDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "syncInterceptor")
public SyncInterceptor getSyncInterceptor() {
return new SyncInterceptor();
}
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource")DataSource datasource,
MybatisProperties mybatisProperties,@Qualifier("syncInterceptor")SyncInterceptor syncInterceptor)
throws Exception{
SqlSessionFactoryBean bean = new SqlSessionFactoryBean