package com.skyline.electricity.utils;
|
|
import org.mybatis.spring.annotation.*;
|
import javax.sql.*;
|
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
import org.springframework.context.annotation.*;
|
import org.springframework.boot.context.properties.*;
|
import org.springframework.beans.factory.annotation.*;
|
import org.apache.ibatis.session.*;
|
import org.springframework.core.io.support.*;
|
import org.springframework.jdbc.datasource.*;
|
import org.mybatis.spring.*;
|
import org.springframework.context.annotation.Configuration;
|
|
@Configuration
|
@MapperScan(basePackages = { "com.skyline.electricity.mapper2" }, sqlSessionTemplateRef = "secondSqlSessionTemplate")
|
public class SecondDataSourceConfig
|
{
|
@Bean(name = { "secondDataSource" })
|
@ConfigurationProperties(prefix = "second.datasource")
|
public DataSource secondDataSource() {
|
return DataSourceBuilder.create().build();
|
}
|
|
@Bean
|
public SqlSessionFactory secondSqlSessionFactory(@Qualifier("secondDataSource") final DataSource dataSource) throws Exception {
|
final SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapping/OutMapper/*.xml"));
|
bean.setDataSource(dataSource);
|
return bean.getObject();
|
}
|
|
@Bean(name = { "secondDataSourceTransactionManger" })
|
public DataSourceTransactionManager masterTransactionManger(@Qualifier("secondDataSource") final DataSource dataSource) {
|
return new DataSourceTransactionManager(dataSource);
|
}
|
|
@Bean
|
public SqlSessionTemplate secondSqlSessionTemplate(@Qualifier("secondSqlSessionFactory") final SqlSessionFactory sqlSessionFactory) {
|
return new SqlSessionTemplate(sqlSessionFactory);
|
}
|
}
|