多源数据加载问题

提问 未结 4 160
wangshaohua
wangshaohua 2019-10-17
悬赏:20积分
版本:renren-security 4.0 浏览器:chrome
配置文件如下: [pre] spring: datasource: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://10.39.35.28:3306/label_flat?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false username: root password: Dzqm@1234 initial-size: 10 max-active: 100 min-idle: 10 max-wait: 60000 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 #Oracle需要打开注释 #validation-query: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: false test-on-return: false stat-view-servlet: enabled: true url-pattern: /druid/* #login-username: admin #login-password: admin filter: stat: log-slow-sql: true slow-sql-millis: 1000 merge-sql: false wall: config: multi-statement-allow: true data: elasticsearch: cluster‐nodes: 10.39.30.95:9300 redis: host: 10.39.30.94 kafka: bootstrap-servers: 10.39.48.113:9092 elasticsearch: url: http://10.39.30.95:9200 ##多数据源的配置,需要引用renren-dynamic-datasource dynamic: datasource: slave1: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://10.39.35.28:3306/uc_interface?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false username: uc_bigdata password: uc_bigdata slave2: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://10.39.35.28:3306/uc_interface?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false username: uc_bigdata password: uc_bigdata kafka: dataacquisition: topic: label-test-customtag groupid: custom-tag [/pre] JAVA代码引用如下: [pre] @DataSource("slave2") @Transactional public void updateUserBySlave2(Long id){ UserAttributeEntity attributeEntity = new UserAttributeEntity(); attributeEntity.setId(id); attributeEntity.setAttrName("13500000000"); userAttributeDao.updateById(attributeEntity); //测试事物 int i = 1/0; } [/pre] 但是从效果上没有实现数据源切换 我用的是renren-api代码,在启动时只有:2019-10-17 15:24:12.514 INFO 9652 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited 加载,同样的方法,我用renren-admin工程就可以运行
回帖
  • 没发现什么问题,debug一下吧
    0 回复
  • wangshaohua
    wangshaohua (楼主)
    2019-10-18
    @Mark 经过debug发现启动renren-admin工程时,能够进入ennuser-dynamic-datasource断点,启动renren-api,没有进入ennuser-dynamic-datasource断点,也就是说启动renren-api的时候,没用注入,这个在配置上有区别吗
    0 回复
  • @wangshaohua 配置上是没有区别的
    0 回复
  • wangshaohua
    wangshaohua (楼主)
    2019-10-18
    @Mark admin工程启动时日志:img[//cdn.renren.io/adeac201910180931589173.png] api工程启动时起至:img[//cdn.renren.io/f626b201910180932265786.png] 我怀疑是不是启动扫描时没有扫描到或者引用冲突?
    0 回复