|
@@ -1,63 +1,63 @@
|
|
|
-package com.idea.config;
|
|
|
-
|
|
|
-import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
-import org.mybatis.spring.SqlSessionTemplate;
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
-import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
-import org.springframework.boot.jdbc.DataSourceBuilder;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
-import tk.mybatis.spring.annotation.MapperScan;
|
|
|
-
|
|
|
-import javax.sql.DataSource;
|
|
|
-
|
|
|
-@Configuration
|
|
|
-@MapperScan(basePackages = "com.slave.**.mapper", sqlSessionFactoryRef = "slaveSqlSessionFactory", sqlSessionTemplateRef = "slaveSqlSessionTemplate")
|
|
|
-public class DataSourcesSlaveConfig {
|
|
|
-
|
|
|
- //主数据源mapper xml文件夹的路径
|
|
|
- private static final String MAPPER_LOCAL_SLAVE = "classpath*:slave/*/*.xml";
|
|
|
-
|
|
|
- /**
|
|
|
- * 是application-test.yml中的spring.datasource.slave配置生效
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Bean(name = "slaveDataSource")
|
|
|
- @ConfigurationProperties(prefix = "spring.datasource.slave")
|
|
|
- public DataSource slaveDataSource() {
|
|
|
- return DataSourceBuilder.create().build();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将配置信息注入到SqlSessionFactoryBean中
|
|
|
- * @param dataSource 数据库连接信息
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @Bean(name = "slaveSqlSessionFactory")
|
|
|
- public SqlSessionFactory slaveSqlSessionFactory(@Qualifier("slaveDataSource") DataSource dataSource) throws Exception {
|
|
|
- return new FactoryUtil().genFactoryBean(dataSource,MAPPER_LOCAL_SLAVE).getObject();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 事务管理器,在实例化时注入主库master
|
|
|
- * @param dataSource
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Bean(name = "slaveTransactionManager")
|
|
|
- public DataSourceTransactionManager slaveTransactionManager(@Qualifier("slaveDataSource") DataSource dataSource) {
|
|
|
- return new DataSourceTransactionManager(dataSource);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * SqlSessionTemplate具有线程安全性
|
|
|
- * @param sqlSessionFactory
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @Bean(name = "slaveSqlSessionTemplate")
|
|
|
- public SqlSessionTemplate slaveSqlSessionTemplate(@Qualifier("slaveSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
|
|
|
- return new SqlSessionTemplate(sqlSessionFactory);
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.idea.config;
|
|
|
+//
|
|
|
+//import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
+//import org.mybatis.spring.SqlSessionTemplate;
|
|
|
+//import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+//import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
+//import org.springframework.boot.jdbc.DataSourceBuilder;
|
|
|
+//import org.springframework.context.annotation.Bean;
|
|
|
+//import org.springframework.context.annotation.Configuration;
|
|
|
+//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
+//import tk.mybatis.spring.annotation.MapperScan;
|
|
|
+//
|
|
|
+//import javax.sql.DataSource;
|
|
|
+//
|
|
|
+//@Configuration
|
|
|
+//@MapperScan(basePackages = "com.slave.**.mapper", sqlSessionFactoryRef = "slaveSqlSessionFactory", sqlSessionTemplateRef = "slaveSqlSessionTemplate")
|
|
|
+//public class DataSourcesSlaveConfig {
|
|
|
+//
|
|
|
+// //主数据源mapper xml文件夹的路径
|
|
|
+// private static final String MAPPER_LOCAL_SLAVE = "classpath*:slave/*/*.xml";
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 是application-test.yml中的spring.datasource.slave配置生效
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Bean(name = "slaveDataSource")
|
|
|
+// @ConfigurationProperties(prefix = "spring.datasource.slave")
|
|
|
+// public DataSource slaveDataSource() {
|
|
|
+// return DataSourceBuilder.create().build();
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 将配置信息注入到SqlSessionFactoryBean中
|
|
|
+// * @param dataSource 数据库连接信息
|
|
|
+// * @return
|
|
|
+// * @throws Exception
|
|
|
+// */
|
|
|
+// @Bean(name = "slaveSqlSessionFactory")
|
|
|
+// public SqlSessionFactory slaveSqlSessionFactory(@Qualifier("slaveDataSource") DataSource dataSource) throws Exception {
|
|
|
+// return new FactoryUtil().genFactoryBean(dataSource,MAPPER_LOCAL_SLAVE).getObject();
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 事务管理器,在实例化时注入主库master
|
|
|
+// * @param dataSource
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Bean(name = "slaveTransactionManager")
|
|
|
+// public DataSourceTransactionManager slaveTransactionManager(@Qualifier("slaveDataSource") DataSource dataSource) {
|
|
|
+// return new DataSourceTransactionManager(dataSource);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * SqlSessionTemplate具有线程安全性
|
|
|
+// * @param sqlSessionFactory
|
|
|
+// * @return
|
|
|
+// * @throws Exception
|
|
|
+// */
|
|
|
+// @Bean(name = "slaveSqlSessionTemplate")
|
|
|
+// public SqlSessionTemplate slaveSqlSessionTemplate(@Qualifier("slaveSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
|
|
|
+// return new SqlSessionTemplate(sqlSessionFactory);
|
|
|
+// }
|
|
|
+//}
|