You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.7 KiB
37 lines
1.7 KiB
5 years ago
|
package com.example.config;
|
||
|
|
||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||
|
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.core.io.support.PathMatchingResourcePatternResolver;
|
||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||
|
|
||
|
import javax.sql.DataSource;
|
||
|
|
||
|
@Configuration
|
||
|
@MapperScan(basePackages = {"com.example.*.twoMpr"}, sqlSessionFactoryRef = "twoSqlSessionFactory")
|
||
|
public class MapperTwoConfig {
|
||
|
@Bean(name = "TwoDataSource")
|
||
|
@ConfigurationProperties(prefix = "spring.datasource.two")
|
||
|
public DataSource dataSource() {
|
||
|
return DataSourceBuilder.create().build();
|
||
|
}
|
||
|
|
||
|
@Bean(name = "twoTransactionManager")
|
||
|
public DataSourceTransactionManager transactionManager(@Qualifier("twoDataSource") DataSource dataSource) {
|
||
|
return new DataSourceTransactionManager(dataSource);
|
||
|
}
|
||
|
|
||
|
@Bean(name = "twoSqlSessionFactory")
|
||
|
public SqlSessionFactory basicSqlSessionFactory(@Qualifier("twoDataSource") DataSource basicDataSource) throws Exception {
|
||
|
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
|
||
|
factoryBean.setDataSource(basicDataSource);
|
||
|
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:com/example/**/twoMpr/*.xml"));
|
||
|
return factoryBean.getObject();
|
||
|
}
|
||
|
}
|