如何仅加载配置文件特定的属性文件并忽略默认的 application.properties? [英] How to load only profile specific property file and ignore default application.properties?

查看:55
本文介绍了如何仅加载配置文件特定的属性文件并忽略默认的 application.properties?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个普通的 spring boot 应用程序,在 resources 文件夹中有两个属性文件:

I have a normal spring boot application, and two property files in resources folder:

application.properties

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

application-dev.properties

com.example.prop1=value11

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

I have some logic based on whether com.example.enableMock is present or missing. Problem is spring loads both files even if spring.profiles.active=dev and the application is getting the com.example.enableMock property.

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

How do I just load profile specific property file?

推荐答案

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

By default application.properties is loaded for any application-*.properties because is shared by following way:

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

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

You can fix this if you put default as profile. Rename application.properties to:

application-default.properties 

这篇关于如何仅加载配置文件特定的属性文件并忽略默认的 application.properties?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆