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

可紊 提交于 2021-02-11 15:00:55

问题


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

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?


回答1:


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

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

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

application-default.properties 


来源:https://stackoverflow.com/questions/54191231/how-to-load-only-profile-specific-property-file-and-ignore-default-application-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!