开发者社区> 问答> 正文

使用druid-spring-boot-starter加载,结合disconf首次读不到jdbc配置

项目使用disconf作为集中配置管理,首次启动是从服务器下载到classpath:application.properties,启动失败,二次启动读取已下载的配置,启动正常。

问题是:autoconfigure直接读不到jdbc配置,然后抛出异常。

org.springframework.context.annotation.AnnotationConfigApplicationContext|WARN|Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dsMaster' defined in class path resource [com/cc/mbb/data/bootstrap/config/DruidDataSourceConfig.class]: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

主要依赖

spring-boot-starter-parent 1.5.10.RELEASE druid-spring-boot-starter 1.1.6

原提问者GitHub用户zhanglei86

展开
收起
山海行 2023-07-05 20:19:52 70 0
2 条回答
写回答
取消 提交回答
  • 北京阿里云ACE会长

    可能是由于以下原因之一:

    Disconf配置未正确加载:如果Disconf配置未正确加载,Druid Spring Boot Starter无法读取JDBC配置。请确保您已正确配置Disconf,并在应用程序启动时成功加载Disconf配置。您可以尝试在启动日志中查找与Disconf加载相关的错误信息,以确定Disconf配置是否正确加载。

    配置文件优先级问题:如果您同时在Disconf和application.yml或application.properties中配置了JDBC信息,可能会导致Druid Spring Boot Starter无法正确读取JDBC配置。请注意,Disconf的配置文件优先级高于application.yml或application.properties,如果Disconf和application.yml或application.properties中存在相同的配置项,Disconf的配置将覆盖application.yml或application.properties中的配置。因此,在使用Disconf时,请确保JDBC配置项的名称和值与Disconf中的配置项相匹配,以确保Druid Spring Boot Starter正确读取JDBC配置。

    缺少必要的依赖项:如果您的应用程序缺少必要的依赖项,可能会导致Druid Spring Boot Starter无法正确读取JDBC配置。请确保您已正确声明Druid Spring Boot Starter和Disconf的依赖,并且所有依赖项都已成功加载。您可以使用Maven或Gradle等构建工具来管理依赖项。

    2023-07-30 14:35:12
    赞同 展开评论 打赏
  • 有两种解决方案:

    1.如果启动Spring Boot时配置文件已经从配置服务器拉取下来了并且以文件的方式保存在本地,可以用 spring.config.location ,这个参数指定外部配置。例如:java -jar app.jar --spring.config.location=/home/admin/application.properties 详情:https://docs.spring.io/spring-boot/docs/1.5.10.RELEASE/reference/htmlsingle/#boot-features-external-config-application-property-files

    2.可以在启动Spring Boot的时候从配置服务器拉取配置,然后追加到Environment里面,这个操作一定确保在初始化Bean的前面。

    原回答者GitHub用户lihengming

    2023-07-06 11:22:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多