New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

是否支持多数据源? #2

Closed
Hishuhong opened this Issue Jul 17, 2017 · 7 comments

Comments

Projects
None yet
5 participants
@Hishuhong
Copy link

Hishuhong commented Jul 17, 2017

多数据源是否可以支持,示例上是否可以加上多数据的解决方案?

@drtrang

This comment has been minimized.

Copy link
Owner

drtrang commented Jul 17, 2017

目前不支持,单纯通过自动配置来实现多数据源是不可行的,如果要添加多数据源功能势必要求用户手动声明 Bean,这似乎违背了 Starter 的初衷。不过我会提供一个多数据源的解决方案,争取下周发布。

@drtrang drtrang added the enhancement label Jul 17, 2017

@drtrang

This comment has been minimized.

Copy link
Owner

drtrang commented Jul 19, 2017

@Hishuhong

1.0.2 版本已发布,新增多数据源支持,请参考 Druid 多数据源支持.mddruid-spring-boot-mybatis-example 中也有相应演示。

@Hishuhong Hishuhong closed this Jul 21, 2017

@michael-ancestor

This comment has been minimized.

Copy link

michael-ancestor commented Dec 13, 2017

@drtrang 整合mybatis的时候,如何实现多数据源?(比如:selectOne()走的是mysql数据源, selectList走的aliyun的ads数据源)是需要手工配置mybatis的SqlSessionFactory吗?比如下面这样:

@Bean(name = "masterSqlSessionFactory")
    @Primary
    public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource)
            throws Exception {
        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(masterDataSource);
        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
                .getResources(MasterDataSourceConfig.MAPPER_LOCATION));
        return sessionFactory.getObject();
    }
@yosaku01

This comment has been minimized.

Copy link

yosaku01 commented Jan 4, 2018

可以考虑Spring的AbstractRoutingDataSource,在调用方法时进行数据源切换

@coolbaobei

This comment has been minimized.

Copy link

coolbaobei commented May 15, 2018

@drtrang 您给的demo访问404

@drtrang

This comment has been minimized.

Copy link
Owner

drtrang commented May 15, 2018

@coolbaobei

代码结构改动较大,最新的地址如下。
多数据源原理:Druid 多数据源支持.md
Demo 演示:druid-spring-boot-mybatis-example

@coolbaobei

This comment has been minimized.

Copy link

coolbaobei commented May 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment