【问题标题】:Spring cloud config not apply global configurationSpring Cloud 配置不应用全局配置
【发布时间】:2021-09-04 15:09:57
【问题描述】:

我在spring cloud配置2020.0.3,spring boot 2.4.5遇到问题,详情:

my_cofig.yaml

spring:
  datasource:
    url: "jdbc:mariadb://localhost:3306/default_db"
    driver-class-name: org.mariadb.jdbc.Driver
    username: my_db
    password: 12345
---
spring:
  profiles: dev
  datasource:
    url: "jdbc:mariadb://localhost:3306/dev_db"
  • 我已经通过浏览器从配置服务器加载了配置,是正确的。 但是:
  • 当我使用特定配置(例如 dev)运行 Spring 应用程序时,Spring 应用程序不能应用配置服务器上配置文件中定义的全局配置变量。它只加载 dev 的配置变量。

bootstrap.yaml

server:
  port: 8081
spring:
  application:
    name: auth-service
  cloud:
    config:
      enabled: true
      fail-fast: true
      allow-override: true
      profile: dev
      uri: http://localhost:5000

错误详情:

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

请帮助我,非常感谢!

【问题讨论】:

  • 此处不可见,但您是否在profiles 中添加了空格? yaml 在空格和制表符方面非常引人注目
  • 感谢您的评论,yaml 格式正确!
  • /actuator/env 说什么?什么版本的spring boot?
  • 我使用的是 Spring Boot 版本:2.4.5。控制台日志:原因:org.hibernate.HibernateException:当未设置“hibernate.dialect”时,对 DialectResolutionInfo 的访问不能为空

标签: spring-boot spring-cloud


【解决方案1】:
spring:
  profiles:

这不存在(如果我没记错的话,它已被弃用)。请查看reference documentation

我相信您正在寻找的是以下内容 (reference documentation):

spring:
  datasource:
    url: "jdbc:mariadb://localhost:3306/default_db"
    driver-class-name: org.mariadb.jdbc.Driver
    username: my_db
    password: 12345
---
spring:
  config:
    activate:
      on-profile: dev
  datasource:
    url: "jdbc:mariadb://localhost:3306/dev_db"

【讨论】:

  • 感谢您的评论,我正在关注Multi-profile YAML documents 编写yaml 配置文件。我已经尝试过您的解决方案,但仍然无法正常工作。
【解决方案2】:

最后,我通过将spring boot版本升级到2.5.1解决了这个问题 谢谢大家

【讨论】:

  • 如果是这种情况,请不要忘记接受您的答案作为正确答案,以便问题呈现为“已回答”;)
猜你喜欢
  • 2015-09-04
  • 2021-04-18
  • 2020-09-27
  • 2015-06-21
  • 1970-01-01
  • 2017-12-10
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
相关资源
最近更新 更多