多个 application.yml 未在 Spring Boot 中合并 [英] Multiple application.yml not merged in Spring Boot

查看:54
本文介绍了多个 application.yml 未在 Spring Boot 中合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于数据库通信的模块(my-db-lib),它被导入到基于spring boot的web应用模块(my-web-app)

I have a module for database communication(my-db-lib), and which is imported to spring boot based web application module(my-web-app)

我想在 my-db-lib 中设置关于 db 的配置,并在 my-web-app

I want to set configuration about db in my-db-lib, and set about web app in my-web-app

  1. my-db-lib 中的 application.yml<代码>D b:网址:本地主机
  2. my-web-app 中的 application.yml<代码>应用程序:留言:你好
  1. application.yml in my-db-lib db: url: localhost
  2. application.yml in my-web-app app: message: hello

my-web-app 运行时,它只能读取app.message 而不是db.url

When my-web-app runs, it can read only app.message not db.url

似乎 yml 文件只是替换为具有最高优先级的文件(不使用配置文件时)这样对吗?我怎样才能达到目的?

It seems that yml files are just replaced with one which has highest priority (when not use profiles) Is it right? How can I achieve purpose?

谢谢,对不起我糟糕的英语 :D

Thanks, And sorry for my poor English :D

推荐答案

子模块中的 application.yml 将被父模块中的 application.yml 覆盖.

The application.yml in child module will be override by application.yml in parent module.

你可以使用这个:

  1. application-my-db-lib.yml 用于模块 my-db-lib
  2. application.yml 用于模块 my-web-app
  1. application-my-db-lib.yml for module my-db-lib
  2. application.yml for module my-web-app

这篇关于多个 application.yml 未在 Spring Boot 中合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆