如何仅加载配置文件特定 属性 文件并忽略默认 application.properties?

How to load only profile specific property file and ignore default application.properties?

我有一个正常的 spring 启动应用程序,resources 文件夹中有两个 属性 文件:

application.properties

com.example.prop1=value1
com.example.enableMock=true

申请-dev.properties

com.example.prop1=value11

我有一些基于 com.example.enableMock 是否存在的逻辑。问题是 spring 加载两个文件,即使 spring.profiles.active=dev 并且应用程序正在获取 com.example.enableMock 属性。

如何只加载配置文件特定的 属性 文件?

默认情况下,为任何 application-*.properties 加载 application.properties,因为通过以下方式共享:

application.properties
     - > application-dev.properties
     - > application-test.properties

如果将 default 作为配置文件,则可以解决此问题。 将 application.properties 重命名为:

application-default.properties