2016-09-06 82 views
2

當且僅當其他配置文件處於活動狀態時,我想用Spring加載額外的.properties文件。例如。如果配置文件「foo」處於活動狀態,我想加載foo.properties。這個僞代碼是我想要的,假設「spring.profiles.active =默認情況下,富」:Spring:根據配置文件加載其他屬性

<context:property-placeholder 
location="classpath:component.properties${(spring.profiles.active).contains('foo') ? ',classpath:foo.properties' : ''}" /> 

有沒有辦法在Spring做到這一點?

+1

我建議將Spring Boot添加到您的應用程序,該應用程序支持此開箱即用。 –

+0

我同意@ M.Deinum,但看到[這個答案](http://stackoverflow.com/questions/28191736/spring-xml-dynamic-property-placeholder-construction/28194233#28194233)它使用SpEL做一些事情通過'properties-ref'間接相似。只要把你的'util:properties'放在配置文件中即可。 –

回答

1

如果您沒有在同一時間處理多個配置文件,則可以這樣使用。

<context:property-placeholder location="classpath:${spring.profiles.active}.properties" /> 
+0

這就是我的問題,我確實有多個配置文件。 –

相關問題