星空下的旅者 2022-08-08 18:16 采纳率: 0%
浏览 65

Springboot + jpa双数据源配置,yml文件问题

Springboot + jpa双数据源配置,yml文件问题

功能介绍:spring boot + jpa 配置两个数据源做数据归档备份,两个数据源按照 primary和secondary分别配置,配置如下:
spring:
datasource:
primary:
jdbc-url: jdbc:mysql://rm-uf6s833icsf5zi2m4r.mysql.rds.aliyuncs.com/license_internal?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
username: sys_dev
password: Sensetime1qaz@WSX
driver-class-name: com.mysql.jdbc.Driver
secondary:
jdbc-url: jdbc:mysql://localhost:3306/license_backup?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
username: root
password: Mjw19931125@
driver-class-name: com.mysql.jdbc.Driver

jpa:
hibernate:
ddl-auto: update
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: true
server:
port: 9999

问题:
程序启动失败,报错提示需要设置数据库,看yml文件像是没有识别jdbc这部分
报错如下:

2022-08-08 17:37:47.867 WARN 28460 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2022-08-08 17:37:47.875 INFO 28460 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-08-08 17:37:47.892 ERROR 28460 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Process finished with exit code 1

想请教各路大神这是为什么,是不是我少了什么配置?

  • 写回答

1条回答 默认 最新

  • 三千烦恼丝xzh 2022-08-08 18:29
    关注

    这要看你如何构建数据源,估计是阿里的Druid,需要把jdbc-url换成url,hikari默认的build就是读取jdbc-url

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 8月8日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度