道路线索应急巡查系统服务后台
feiyu02
2025-04-22 41548e262362faf603a71e066e01bd4ef46619d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.flightfeather.grid.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.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
 
 
/**
 * Mybatis  第二个ds2数据源配置
 * 多数据源配置依赖数据源配置
 * @see  DataSourceConfig
 */
@Configuration
@MapperScan(basePackages = ["com.flightfeather.grid.domain.ds2.mapper"],
    sqlSessionTemplateRef = "ds2SqlSessionTemplate")
class MybatisConfig4ds2 {
 
    //ds2数据源
    @Bean("ds2SqlSessionFactory")
    @Throws(Exception::class)
    fun ds2SqlSessionFactory(@Qualifier("ds2DataSource") dataSource: DataSource?): SqlSessionFactory? {
        val sqlSessionFactory = SqlSessionFactoryBean()
        sqlSessionFactory.setDataSource(dataSource)
        sqlSessionFactory.setMapperLocations(*PathMatchingResourcePatternResolver().getResources("classpath*:mapper/ds2/*.xml"))
        return sqlSessionFactory.getObject()
    }
 
    //事务支持
    @Bean(name = ["ds2TransactionManager"])
    fun ds2TransactionManager(@Qualifier("ds2DataSource") dataSource: DataSource): DataSourceTransactionManager? {
        return DataSourceTransactionManager(dataSource)
    }
 
    @Bean(name = ["ds2SqlSessionTemplate"])
    fun ds2SqlSessionTemplate(@Qualifier("ds2SqlSessionFactory") sqlSessionFactory: SqlSessionFactory?): SqlSessionTemplate? {
        return SqlSessionTemplate(sqlSessionFactory)
    }
}