我的多数据源配置不生效,分页信息都没传到sql里
yaozhigangyeah opened this issue · 6 comments
yaozhigangyeah commented
我的多数据源是这样配置的,不用切换
@configuration
@MapperScan(basePackages = "com.lingdong.business.mapper,com.lingdong.mapper",sqlSessionTemplateRef ="firstSqlSessionTemplate")
public class FirstDataSourceConfig {
@Autowired
private FirstDataBaseProperties prop;
/**创建数据源*/
@Bean(name = "firstDS")
@ConfigurationProperties(prefix = "spring.datasource.first")
@Primary
public DataSource getFirstDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(prop.driverClassName);
dataSource.setUrl(prop.url);
dataSource.setUsername(prop.username);
dataSource.setPassword(prop.password);
return dataSource;
}
/**创建SessionFactory*/
@Bean(name = "firstSqlSessionFactory")
@Primary
public SqlSessionFactory firstSqlSessionFactory(@Qualifier("firstDS") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setTypeAliasesPackage("com.lingdong.bean,com.lingdong.bean.business");
Resource[] mapperLocations1 = new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml");
Resource[] mapperLocations2 = new PathMatchingResourcePatternResolver().getResources("classpath*:business/mapper/*.xml");
Resource[] mapperLocations = new Resource[mapperLocations1.length+mapperLocations2.length];
int inx = 0;
for(Resource r:mapperLocations1){
mapperLocations[inx++] = r;
}
for(Resource r:mapperLocations2){
mapperLocations[inx++] = r;
}
bean.setMapperLocations(mapperLocations);
return bean.getObject();
}
bes2008 commented
yaozhigangyeah commented
那应该怎样配置多数据源,是要配置成动态切换吗
bes2008 commented
yaozhigangyeah commented
this.sqlHelperMybatisProperties怎么来的
bes2008 commented
springboot application.yml,有默认值,可以不配置
可以去看看sqlhelper-examples 中的例子
另外,有专门的QQ群,你可以在群里直接问,QQ群就在首页可以找到
bes2008 commented
另外告诉你一个小技巧,很多情况下,根本不必自己去定义SQLSessionFactory的,可以看一下 ConfigurationCustomizer这个类