spring-boot - Spring Cloud 配置不应用全局配置
问题描述
我在 spring cloud 配置 2020.0.3、spring boot 2.4.5 上遇到问题,详情:
- Yaml 配置文件在Multi-profile YAML 文档之后
- 我在配置服务器上有一个配置 yaml 文件。
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 的配置变量。
引导程序.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
请帮助我,非常感谢!
解决方案
spring:
profiles:
This does not exist (it was deprecated if I am not mistaken). Please check the reference documentation.
I believe that what you are looking for is the following (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"
推荐阅读
- java - Java有时在读取文件时返回空字符串
- finance - *TradingView Pine* 止盈警报不起作用
- apache - 您可以将“/.html”的请求准确地重定向到 index.html 吗?
- java - 如何计算我的程序中的年差?
- traefik - Traefik - 重定向和斜杠
- maxima - 如何告诉 Maxima 使用更多内存?
- python - python scipy内置函数ODEINT使用不同的时间点集(参数t)
- python - 在熊猫中按日期对前 n 个值进行分组
- flash - 我需要 ATtiny1617 的引导加载程序吗
- php - Ajax 请求发送 CURL 请求