Loading environment specific properties file in spring

落花浮王杯 提交于 2019-12-23 23:50:26

问题


I am working on a spring-boot application, I need your assistance on below scenario.

I have properties files for each environment something like application-dev.properties, application-prod.properties etc. Is there way that my application can load environment specific properties file by using spring @Profile annotation.

Please help.


回答1:


You don't need to use @Profiles annotation at all. Just use

@ConfigurationProperties(locations = "classpath:myapp-${environment.type}.properties")

and define environment type via system property. E.g. via command line -Denvironment.type=dev.



来源:https://stackoverflow.com/questions/34394054/loading-environment-specific-properties-file-in-spring

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