一、除了Mysql驱动,我们还需要用到postgresql的驱动,所以我们先把驱动的依赖给导入进来 org.postgresql postgresql
org.postgresql postgresql
# 数据源配置spring: datasource: type: com.alibaba.druid.pool.DruidDataSource druid: # 主库数据源 master: driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/i_ren_shi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root passWord: root # 从库数据源 slave: # 从数据源开关/默认关闭 enabled: true driverClassName: org.postgresql.Driver url: jdbc:postgresql://localhost:5432/easytrack username: 123456 password: 123456 easytrack: # 从数据源开关/默认关闭 enabled: true driverClassName: org.postgresql.Driver url: jdbc:postgresql://localhost:5432/easytrack username: 123456 password: 123456
package com.ruoyi.common.enums;public enum DataSourceType{ MASTER, SLAVE, EASYTRACK}
@Bean @ConfigurationProperties("spring.datasource.druid.easytrack") @ConditionalOnProperty(prefix = "spring.datasource.druid.easytrack", name = "enabled", havingValue = "true") public DataSource easyTrackDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); return druidProperties.dataSource(dataSource); } @Bean(name = "dynamicDataSource") @Primary public DynamicDataSource dataSource(DataSource masterDataSource) { Map
@DataSource(value = DataSourceType.EASYTRACK)
来源地址:https://blog.csdn.net/Hui_Hong_TaiLang/article/details/130842296
--结束END--
本文标题: ruoyi(若依)配置多数据源(mysql+postgresql),rouyi(Springboot)多数据源设置
本文链接: https://www.lsjlt.com/news/372831.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-13
2024-05-13
2024-05-13
2024-05-13
2024-05-12
2024-05-12
2024-05-12
2024-05-12
2024-05-12
2024-05-12
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0