SpringBoot多数据源

配置文件

logging:
  config: classpath:log4j2.xml
eureka:
  instance:
    preferIpAddress: true
  client:
    serviceUrl:
      defaultZone: http://XXX.XXXX.XXX.XXXX:XXXX/eureka/
    healthcheck:
      enabled: false
server:
  port: 9527
management:
  security:
    enabled: false
endpoints:
  health:
    sensitive: false
spring:
  application:
    name: telecom-cloud-collection
mybatis:
  mapper-locations: classpath*:mapper/**/*.xml
  type-aliases-package: com.chinamobile.cmss.telecom.cloud
  type-handlers-package: com.eyougo.mybatis.postgis.type
  config-location: classpath:/mybatis-config.xml
  configuration:
    log-impl: org.apache.ibatis.logging.log4j2.Log4j2Impl

datasource:
  names: resources,dataCenter
  resources:
    write:
      url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/rms_province
      username: postgres
      password: postgres
      driver-class-name: org.postgresql.Driver
      type: com.alibaba.druid.pool.DruidDataSource
    read:
      names: read01,read02,read03
      readSize: 3  #读库个数
      weights: 3,3,4 #读库权重
      class: com.chinamobile.cmss.gvrms.datasource.read.WeightsReadStrategy
      read01:
        url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/rms_province
        username: postgres
        password: postgres
        driver-class-name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
      read02:
        url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/rms_province
        username: postgres
        password: postgres
        driver-class-name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
      read03:
        url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/rms_province
        username: postgres
        password: postgres
        driver-class-name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
  dataCenter:
    write:
      url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/nanjingfgm?currentSchema=cmss&useUnicode=true&characterEncoding=UTF-8&allowMultiQuer
      username: postgres
      password: postgres
      driver-class-name: org.postgresql.Driver
      type: com.alibaba.druid.pool.DruidDataSource
    read:
      names: o4Center
      o4Center:
        url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/nanjingfgm?currentSchema=cmss&useUnicode=true&characterEncoding=UTF-8&allowMultiQuer
        username: postgres
        password: postgres
        driver-class-name: org.postgresql.Driver
        type: com.alibaba.druid.pool.DruidDataSource
  minIdle: 5
  maxActive: 10
  initialSize: 2
  maxWait: 60000
  timeBetweenEvictionRunsMillis: -1
  minEvictableIdleTimeMillis: 300000
  validationQuery: select 'x'
  testWhileIdle: true
  testOnBorrow: false
  testOnReturn: false
  poolPreparedStatements: true
  maxPoolPreparedStatementPerConnectionSize: 50
  removeAbandoned: false
  filters: stat


feign:
  hystrix:
    enabled: true

hystrix:
  threadpool:
    default:
      coreSize: 200
      maxQueueSize: 200
      queueSizeRejectionThreshold: 50
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 300000
      circuitBreaker:
        sleepWindowInMilliseconds: 300000
        forceClosed: true
ribbon:
  ReadTimeout: 300000
  SocketTimeout: 300000
  ConnectTimeout: 300000
  OkToRetryOnAllOperations: true
  MaxAutoRetries: 1
  MaxAutoRetriesNextServer: 2

注解


@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface WriteDataSource {

    /**
     * 默认使用resources集群库
     * @return
     */
    String name() default "resources";

    /**
     * 具体数据库
     * @return
     */
    String database() default "";
}

java文件

/**
 * Created by 18317 on 2019/11/24.
 */
@Service
@Slf4j
@WriteDataSource(name = "dataCenter", database = "o4Center")
public class ONfvoCmVnfDService {

    @Autowired
    private ONfvoCmVnfDMapper oNfvoCmVnfDMapper;

    public List<ONfvoCmVnfD> selectByNowDate () {
        return oNfvoCmVnfDMapper.selectByNowDate();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值