zoukankan      html  css  js  c++  java
  • Configure Two DataSources ---

    67. Data Access

    67.1 Configure a DataSource

    To override the default settings just define a @Bean of your own of type DataSource. Spring Boot provides a utility builder class DataSourceBuilder that can be used to create one of the standard ones (if it is on the classpath), or you can just create your own, and bind it to a set of Environment properties e.g.

    @Bean
    @ConfigurationProperties(prefix="datasource.mine")
    public DataSource dataSource() {
        return new FancyDataSource();
    }
    datasource.mine.jdbcUrl=jdbc:h2:mem:mydb
    datasource.mine.user=sa
    datasource.mine.poolSize=30

    See Section 28.1, “Configure a DataSource” in the ‘Spring Boot features’ section and the DataSourceAutoConfiguration class for more details.

    67.2 Configure Two DataSources

    Creating more than one data source works the same as creating the first one. You might want to mark one of them as @Primary if you are using the default auto-configuration for JDBC or JPA (then that one will be picked up by any @Autowired injections).

    @Bean
    @Primary
    @ConfigurationProperties(prefix="datasource.primary")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }
    
    @Bean
    @ConfigurationProperties(prefix="datasource.secondary")
    public DataSource secondaryDataSource() {
        return DataSourceBuilder.create().build();
    }

    http://docs.spring.io/spring-boot/docs/1.2.0.BUILD-SNAPSHOT/reference/htmlsingle/

  • 相关阅读:
    【译文】HTML5 Canvas的点击区域检测以及如何监听Canvas上各种图形的点击事件
    快速排序法精简理解
    数据结构--堆
    数据结构--哈希表
    数据结构--队列
    数据结构--栈
    数据结构--数组
    数据结构--链表
    算法的基本知识
    Arthas
  • 原文地址:https://www.cnblogs.com/softidea/p/6117919.html
Copyright © 2011-2022 走看看