yangys
2025-09-19 9a5abe507d6602f2311ffbe1d7bf25e2b58d3a7a
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
package org.springblade.qinzhesync.config;
 
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
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.core.JdbcTemplate;
 
import javax.sql.DataSource;
 
@Configuration
public class JdbcTemplateConfig {
    private String mapper = "classpath:org/springblade/qinzhesync/mapper/*Mapper.xml";   //xml扫描路径
    //private String mapper = "org/springblade/qinzhesync/mapper/*Mapper.xml";   //xml扫描路径
    @Primary
    @Bean
    public JdbcTemplate primaryJdbcTemplate(@Qualifier("mdmDdataSource") DataSource dataSource) {//
        return new JdbcTemplate(dataSource);
    }
 
    @Bean
    public JdbcTemplate qinzheJdbcTemplate(@Qualifier("qinzheDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
 
    @Bean
    public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
        final SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setTypeAliasesPackage("org.springblade.qinzhesync.entity");
        //sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapper));
        return sqlSessionFactoryBean.getObject();
    }
}