Home > Back-end >  Multiple source of transaction management
Multiple source of transaction management

Time:04-08

@ Configuration
@ MapperScan ( basePackages={
"Org.com.dao.backMaster"
}, sqlSessionFactoryRef="backMasterSqlSessionFactory sqlSessionTemplateRef=" backMasterSqlSessionTemplate ")
Public class SqlSessionFactoryBackMaster {

@ Bean (name="backMaster")
@ ConfigurationProperties (prefix="spring. The datasource. Backmaster")
Public HikariDataSource backMaster () {
Return DataSourceBuilder. The create (). The type (HikariDataSource. Class). The build ();
}

@ Bean (name="backMasterSqlSessionFactory")
Public SqlSessionFactory backMasterSqlSessionFactory (
@ the Qualifier (" backMaster ") the DataSource backMaster) throws the Exception {
SqlSessionFactoryBean factoryBean=new SqlSessionFactoryBean ();
FactoryBean. SetDataSource (backMaster);
FactoryBean. SetMapperLocations (new PathMatchingResourcePatternResolver ()
GetResources (" classpath: org/com/dao/backMaster/*. XML ") );
FactoryBean. SetConfigLocation (
New DefaultResourceLoader (). GetResource (" classpath: mybatis - config. XML "));
Return factoryBean. GetObject ();
}

@ Bean (name="backMasterTransactionManager")
Public DataSourceTransactionManager backMasterTransactionManager () {
Return new DataSourceTransactionManager (backMaster ());
}

@ Bean (name="backMasterSqlSessionTemplate")
Public SqlSessionTemplate backMasterSqlSessionTemplate () throws the Exception {
SqlSessionTemplate template=new SqlSessionTemplate (
BackMasterSqlSessionFactory (backMaster ()));
Return the template.
}
}

To ask you, the red is the scope of the transaction management bean ah
  • Related