spring-mvc - Spring MVC application.properties 未被配置文件 application-dev.properties 覆盖

标签 spring-mvc properties overriding profile

我正在寻找一种方法来根据 JVM 环境变量配置不同的 application.properties 文件。

我在 Spring 引用资料中找到了这个文档。

In addition to application.properties files, profile-specific properties can also be defined using the naming convention application-{profile}.properties.

Profile specific properties are loaded from the same locations as standard application.properties, with profile-specific files always overriding the default ones irrespective of whether the profile-specific files are inside or outside your packaged jar.

然后我就这样做了:

Configuration structure

然后在我的 JVM 选项中添加一个 -Dspring.profiles.active=dev

Profile option for JVM

我试图查看我在 dev 中的参数是否被使用,但事实并非如此。应用程序从 application.properties 文件加载数据。

知道为什么吗?

最佳答案

尝试将默认属性文件的名称修改为“application-default.properties”,如文档中所述:

The Environment has a set of default profiles (by default [default]) which are used if no active profiles are set (i.e. if no profiles are explicitly activated then properties from application-default.properties are loaded).

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-profile-specific-properties

关于spring-mvc - Spring MVC application.properties 未被配置文件 application-dev.properties 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649089/

相关文章:

c# - 如何覆盖而不是隐藏 C# 子类中的成员变量(字段)?

spring-mvc - Spring Boot 提供内容类型错误的静态 .webm 和 .mp4 文件

java - SpringMVC HTTP 状态 404 -

spring - 无法启动网络关闭的引导项目

java - Spring 安全 : enable/disable CSRF by client type (browser/non-browser )

c# - 如何在 ISO C++ 中定义或实现 C# 属性?

java - 从外部目录加载属性文件

ios - 在 Objective-C 中共享数据对象的最佳方式是什么?

Scala: "override protected val"在定义案例类构造函数时导致错误

无法识别 C++ 虚函数