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
想请教各路大神这是为什么,是不是我少了什么配置?