![](/img/trans.png)
[英]PropertyPlaceholderConfigurer and PropertySourcesPlaceholderConfigurer run differently
[英]PropertySourcesPlaceholderConfigurer and PropertyPlaceholderConfigurer
我對遺留代碼(它的Spring應用程序)進行了分析,發現在Spring上下文中初始化了PropertySourcesPlaceholderConfigurer
和PropertyPlaceholderConfigurer
。 我知道在Spring上下文中只應存在一個PropertyPlaceholderConfigurer
實例。 我的問題是,這個規則是否適用於PropertySourcesPlaceholderConfigurer
和PropertyPlaceholderConfigurer
。 將它們都納入背景是錯誤的嗎?
可以注冊多個屬性配置。 但是如果PlaceholderConfigurer都引用了同一組屬性,那么它的配置錯誤就應該避免。
否則,在注冊多個PlaceholderConfigurer時,正確指定bean的順序非常重要。 因此Spring可以為占位符解析正確的值。
你可以在這里找到一個好的閱讀。
PropertySourcesPlaceholderConfigurer通過利用Spring 3.1中提供的Environment和PropertySource機制更加靈活。
PropertyPlaceholderConfigurer仍然適合在以下情況下使用:
PropertySourcesPlaceholderConfigurer此類被設計為Spring 3.1應用程序中PropertyPlaceholderConfigurer的一般替代品。 默認情況下,它使用property-placeholder元素來支持spring-context-3.1 XSD,而spring-context version <= 3.0默認使用PropertyPlaceholderConfigurer來確保向后兼容性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.