我正在寻找一种方法来根据 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.
然后我就这样做了:
然后在我的 JVM 选项中添加一个 -Dspring.profiles.active=dev
。
我试图查看我在 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).
关于spring-mvc - Spring MVC application.properties 未被配置文件 application-dev.properties 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649089/