I want to change ExecutorType and define MapperScan in a project using Spring and MyBatis DataSorce uses the same and changes only ExecutorType to BATCH, REUSE Applies to processes that perform multiple updates of BATCH, REUSE applies to others MapperScan could be defined in the same class
SqlSessionConfig.java
@Configuration
public class SqlSessionConfig {
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource datasource) throws Exception {
SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
sqlSessionFactory.setDataSource(datasource);
return (SqlSessionFactory) sqlSessionFactory.getObject();
}
@Bean(name = "defaultSqlSessionTemplate")
public SqlSessionTemplate sqlSessionFactory(SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean(name = "reuseSqlSessionTemplate")
public SqlSessionTemplate sqlSessionFactory(SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory, ExecutorType.REUSE);
}
@Bean(name = "batchSqlSessionTemplate")
public SqlSessionTemplate sqlSessionFactory(SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory, ExecutorType.BATCH);
}
}
@MapperScan(basePackages = "jp.co.sample.mapper.defaul", sqlSessionTemplateRef = "defaultSqlSessionTemplate")
class DefaultMapperScan {
}
@MapperScan(basePackages = "jp.co.sample.mapper.reuse", sqlSessionTemplateRef = "reuseSqlSessionTemplate")
class ReuseMapperScan {
}
@MapperScan(basePackages = "jp.co.sample.mapper.batch", sqlSessionTemplateRef = "batchSqlSessionTemplate")
class BatchMapperScan {
}