package com.hx.phip.config;
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
import org.mybatis.spring.SqlSessionTemplate;
|
import org.mybatis.spring.annotation.MapperScan;
|
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.context.annotation.Primary;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
import javax.sql.DataSource;
|
|
/**
|
* Druid配置类
|
*/
|
//@Configuration
|
//@MapperScan(basePackages = "com.hx.phip.dao.mapper.syn", sqlSessionTemplateRef = "synSqlSessionTemplate")
|
public class DataSourceSynConfig {
|
|
@Bean(name = "synDataSource")
|
@ConfigurationProperties(prefix = "spring.datasource.syn")
|
|
public DataSource testDataSource() {
|
return DataSourceBuilder.create().build();
|
}
|
|
@Bean(name = "synSqlSessionFactory")
|
public SqlSessionFactory testSqlSessionFactory(@Qualifier("synDataSource") DataSource dataSource) throws Exception {
|
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
bean.setDataSource(dataSource);
|
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/syn/*.xml"));
|
return bean.getObject();
|
}
|
|
@Bean(name = "synTransactionManager")
|
public DataSourceTransactionManager testTransactionManager(@Qualifier("synDataSource") DataSource dataSource) {
|
return new DataSourceTransactionManager(dataSource);
|
}
|
|
@Bean(name = "synSqlSessionTemplate")
|
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("synSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
|
return new SqlSessionTemplate(sqlSessionFactory);
|
}
|
|
}
|