<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
</dependency>
spring.datasource.druid.mysql2.url=jdbc:mysql://47.93.56.27:14217/sci_industrial?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&autoReconnect=true&useSSL=false
spring.datasource.druid.mysql2.user=root
spring.datasource.druid.mysql2.password=123456
spring.datasource.druid.mysql2.url=jdbc:mysql://47.93.56.28:14217/sci_industrial?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&autoReconnect=true&useSSL=false
spring.datasource.druid.mysql2.user=root
spring.datasource.druid.mysql2.password=123456
@Data
@Configuration
@MapperScan(basePackages = "com.sci.dataInt.mapper.mysql", sqlSessionFactoryRef = "mysql")
public class MysqlDataBaseConfig {
private static final String MAPPER_LOCATION = "classpath:mapper/mysql/*.xml";
@Bean
@ConfigurationProperties("spring.datasource.druid.mysql")
public Properties testOneProperties() {
return new Properties();
}
@Bean(name = "testOneDataSource")
public DataSource testOneDataSource() {
AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
Properties prop = testOneProperties();
ds.setXaDataSourceClassName("com.mysql.cj.jdbc.MysqlXADataSource");
ds.setUniqueResourceName("testOne");
ds.setXaProperties(prop);
return ds;
}
@Bean(name = "mysql")
public SqlSessionFactory primarySqlSessionFactory(@Qualifier("testOneDataSource") DataSource dataSource,
@Autowired(required = false) Interceptor interceptor) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));
sessionFactory.setPlugins(interceptor);
org.apache.ibatis.session.Configuration ibatisConfiguration = new org.apache.ibatis.session.Configuration();
ibatisConfiguration.setMapUnderscoreToCamelCase(true);
sessionFactory.setConfiguration(ibatisConfiguration);
return sessionFactory.getObject();
}
@Bean(name = "mysqlTemplate")
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("mysql") SqlSessionFactory primarySqlSessionFactory) throws Exception {
return new SqlSessionTemplate(primarySqlSessionFactory);
}
}
@MapperScan(basePackages = "com.sci.dataInt.mapper.mysql2",sqlSessionFactoryRef = "mysql2")
public class MysqlDataBaseConfig1 {
private static final String MAPPER_LOCATION = "classpath:mapper/mysql2/*.xml";
@Bean
@ConfigurationProperties("spring.datasource.druid.mysql2")
public Properties testM2Properties() {
return new Properties();
}
@Bean(name = "testTwoDataSource")
public DataSource testTwoDataSource() {
AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
Properties prop = testM2Properties();
ds.setXaDataSourceClassName("com.mysql.cj.jdbc.MysqlXADataSource");
ds.setUniqueResourceName("testTwo");
ds.setXaProperties(prop);
return ds;
}
@Bean(name = "mysql2")
public SqlSessionFactory primarySqlSessionFactory(@Qualifier("testTwoDataSource") DataSource dataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));
org.apache.ibatis.session.Configuration ibatisConfiguration = new org.apache.ibatis.session.Configuration();
ibatisConfiguration.setMapUnderscoreToCamelCase(true);
sessionFactory.setConfiguration(ibatisConfiguration);
return sessionFactory.getObject();
}
@Bean(name = "mysqlTemplate2")
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("mysql2") SqlSessionFactory primarySqlSessionFactory) throws Exception {
return new SqlSessionTemplate(primarySqlSessionFactory);
}
}
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)