在Spring Boot中覆盖配置文件属性

a3dsfcv:

在春季启动中,我具有以下配置文件:application-email.yaml

services:
  email:
    cron: '....'
    recipient: `...`
    other properties...

在test / resources目录中,我具有application.yaml,我希望包括电子邮件配置文件中的所有属性,但是对于测试,我想覆盖该recipient属性。

所以我希望我的application.yaml看起来像这样:

spring:
  profiles:
    include: email

services:
  email:
    recipient: `test-email`

就我所知,首先test / resources中读取application.yaml,然后用配置文件中的值覆盖它。但我要相反。

我该如何实现?

补充1:我认为我可以创建个人档案测试,在此处定义我的测试收件人。但是,如果没有其他个人资料,我可以这样做吗?

时间:

最好的方法确实是创建一个application-test.yaml并激活配置文件测试。

您为什么不想这样做?这是春季推荐的方式。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot属性与依赖项中的配置文件

在Spring配置文件中的bean属性中覆盖属性值$ {abc.xyz}

使用PropertiesLauncher启动的Spring-boot(特定于配置文件)应用程序中的问题覆盖应用程序属性

Spring Boot配置文件不选择属性文件

Spring Boot未根据配置文件读取正确的属性

Spring boot 静态内容包括配置文件属性

具有外部属性的Spring Boot配置文件

根据系统属性在Spring Boot应用程序中设置配置文件

我可以在Spring Boot配置文件中定义系统属性吗?

在Spring Boot中如何同时使用来自不同配置文件的属性?

在spring boot @activeprofile注释中配置Maven配置文件

Spring Boot:在PropertySourcesPlaceholderConfigurer加载的文件中忽略了配置文件

在Spring-boot中设置默认的活动配置文件

将Spring Boot配置文件组织到目录中

从POM中的Maven配置文件进行Spring Boot

在Spring Boot中从默认配置文件yml删除密钥

Spring Boot中的加载配置文件问题

Spring 配置文件属性值在 yaml 文件中被覆盖

在Spring Boot中继承配置文件

Spring Boot属性取决于特定于配置文件的属性

Spring Boot-使用配置文件时不读取默认属性文件

Spring Boot 找不到特定于配置文件的属性文件

如果有多个配置文件,则不会选择 Spring Boot 中的默认配置文件

Spring Boot Pom-如何从聚合器Pom继承配置文件和属性?

Spring Boot多个具有相同名称和相同属性名称的配置文件

Spring Boot无法读取配置文件表达式内的属性

通过配置文件使用Yaml属性进行Spring Boot测试

在Spring Boot中从命令行设置活动配置文件和配置位置

使用 Docker Compose 覆盖 Spring 活动配置文件