当前使用版本(必填,否则不予处理)
3.4.3.3
该问题是如何引起的?(确定最新版也有问题再提!!!)
配置了多数据源,代码如下(另一个DataSourceConfig格式一样),在使用saveBatch方法的时候,没有采用Service对应Mapper的数据源,而是使用了另一个数据源
@Configuration @MapperScan(basePackages ="com.xx.xx.mapper", sqlSessionTemplateRef = "sqlSessionTemplate") public class DataSourceConfig {
@Value("${mybatis-plus.mapper-locations}")
private String mapperLocations;
@Value("${mybatis-plus.type-aliases-package}")
private String typeAliasesPackage;
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Bean
@ConfigurationProperties(prefix = "mybatis-plus.global-config")
public GlobalConfig globalConfig(){
return new GlobalConfig();
}
@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource dataSource() {
return DruidDataSourceBuilder.create().build();
}
@Bean
@Primary
public PlatformTransactionManager transactionManager(@Qualifier("dataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
public ChainedTransactionManager chainedTransactionManager(
@Qualifier("transactionManager") PlatformTransactionManager transactionManager,
@Qualifier("transactionManagerCEC") PlatformTransactionManager transactionManagerCEC) {
return new ChainedTransactionManager(transactionManager, transactionManagerCEC);
}
@Bean
@Primary
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource,
@Qualifier("globalConfig") GlobalConfig globalConfig,
MybatisPlusInterceptor paginationInterceptor,
@Qualifier("fullSqlInjector") ISqlInjector fullSqlInjector) throws Exception {
MybatisSqlSessionFactoryBean sf = new MybatisSqlSessionFactoryBean();
sf.setDataSource(dataSource);
sf.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
sf.setTypeAliasesPackage(typeAliasesPackage);
globalConfig.setSqlInjector(fullSqlInjector);
sf.setGlobalConfig(globalConfig);
sf.setPlugins(paginationInterceptor);
return sf;
}
@Bean
@Primary
public SqlSessionTemplate sqlSessionTemplate(@Qualifier("sqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
重现步骤(如果有就写完整)
报错信息
Comment From: ooizj
找到原因了,忘了分别设置mapper.xml的位置了 MybatisSqlSessionFactoryBean sf = new MybatisSqlSessionFactoryBean(); sf.setMapperLocations(...);