无法正常连接配置文件中的数据库,Failed to determine suitable jdbc url

Blade 未结 1 393
frizab
frizab 剑童 2023-11-08 09:10

一、该问题的重现步骤是什么?

1. 创建一个独立于BladeX外的微服务,依赖于bladex框架,pom参考bladex的服务引入包

2. 创建common并参考blade-common,配置与bladex使用的同一个nacos

3. 将数据库相关的配置写在resource的配置文件中或者nacos中都无法正常连接数据库

*具体请参考步骤5中的补充图片


二、你期待的结果是什么?实际看到的又是什么?

期待的结果为:正常连接数据库并启动服务

实际的结果为:启动失败,Failed to determine suitable jdbc url


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

正在使用的是BladeX 3.1.0 RELEASE,在windows10的idea上开发,nacos等组件安装在虚拟机的CentOS7上


四、请提供详细的错误堆栈信息,这很重要。

WARN 18552 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'prometheusMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourcePoolMetadataMeterBinder' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourcePoolMetadataMeterBinder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine suitable jdbc url

INFO 18552 --- [           main] ConditionEvaluationReportLoggingListener : 


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

ERROR 18552 --- [           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 suitable jdbc url


五、若有更多详细信息,请在下面提供。

图片_20231108090141.png

参考https://sns.bladex.cn/q-5408.html的解决办法,在Configuration文件添加注解,开启动态数据库,未解决问题

正常填写数据库连接,如

jdbc:mysql://x.x.x.x:3306/xxx?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true

或者使用nacos中的

图片_20231108090153.png

url: ${jcgkzx.datasource.dev.url}

或者干脆使用与bladex相同的数据库配置

url: ${blade.datasource.dev.url}

都无法正常连接到数据库

数据库无异常,bladex服务可以正常运行


1条回答
  • 2023-11-23 15:57
    org.springframework.bootspring-boot-maven-pluginsrc/main/java**/*.yml**/*.properties**/*.xmlfalsesrc/main/resources**/*.yml**/*.properties**/*.xmlfalselib**/*.jar

    pom.xml中添加这个

    作者追问:2023-11-23 15:58

    被xss给过滤了,麻烦再发一下配置,要用编辑器的代码语言框住配置发出来才可以

    image.png

    0 讨论(0)
提交回复