gpt4 book ai didi

java - 如何在 Spring 配置中导入用于生产的可选属性文件?

转载 作者:行者123 更新时间:2023-11-30 09:09:54 25 4
gpt4 key购买 nike

我想配置 Spring 以在生产期间覆盖某些属性,但只有(!)如果找到 production.properties 文件并且仅针对它的属性定义。但是这些限制应该只适用于这个生产文件。所有其他属性文件都应该是必需的。

但是我不能在 spring 配置中导入两个不同的属性资源。我需要更改什么?

@Configuration
@PropertySource({"classpath:default.properties"})
@PropertySource({"file:production.properties"}, ignoreResourceNotFound = true) //Error: Duplicate annotation

最佳答案

试试PropertySources注解,它是一个聚合了多个PropertySource注解的容器注解。

关于java - 如何在 Spring 配置中导入用于生产的可选属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22784577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com