package com.dy.common.multiDataSource;
|
|
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
@Configuration
|
public class MultiDataSourceConfig {
|
|
@Autowired
|
private javax.sql.DataSource multiDataSource;
|
|
@Bean(name = "sqlSessionFactory")
|
public MybatisSqlSessionFactoryBean sqlSessionFactory() throws Exception {
|
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
|
bean.setTransactionFactory(new MultiDataSourceTransactionFactory());
|
bean.setDataSource(multiDataSource);
|
|
/**
|
* 刘润玉 2023-10-11
|
* 因为BasePo不必要了,所以MetaObjectHandler也不需要了,进而MultiDataSourceConfig
|
* 中的相关代码也不需要了。
|
//mybatisplus 全局配置
|
GlobalConfig globalConfig = new GlobalConfig();
|
//配置填充器
|
globalConfig.setMetaObjectHandler(new MetaObjectHandler());
|
bean.setGlobalConfig(globalConfig);
|
*/
|
|
//设置我们的xml文件路径
|
Resource[] resources = new PathMatchingResourcePatternResolver().getResources(
|
"classpath*:mapper/*.xml") ;
|
bean.setMapperLocations(resources);
|
return bean ;
|
|
}
|
}
|