簡體   English   中英

PropertySourcesPlaceholderConfigurer和PropertyPlaceholderConfigurer

[英]PropertySourcesPlaceholderConfigurer and PropertyPlaceholderConfigurer

我對遺留代碼(它的Spring應用程序)進行了分析,發現在Spring上下文中初始化了PropertySourcesPlaceholderConfigurerPropertyPlaceholderConfigurer 我知道在Spring上下文中只應存在一個PropertyPlaceholderConfigurer實例。 我的問題是,這個規則是否適用於PropertySourcesPlaceholderConfigurerPropertyPlaceholderConfigurer 將它們都納入背景是錯誤的嗎?

可以注冊多個屬性配置。 但是如果PlaceholderConfigurer都引用了同一組屬性,那么它的配置錯誤就應該避免。

否則,在注冊多個PlaceholderConfigurer時,正確指定bean的順序非常重要。 因此Spring可以為占位符解析正確的值。

你可以在這里找到一個好的閱讀。

Spring屬性

PropertySourcesPlaceholderConfigurer通過利用Spring 3.1中提供的Environment和PropertySource機制更加靈活。

PropertyPlaceholderConfigurer仍然適合在以下情況下使用:

  1. spring-context模塊不可用(即,一個使用Spring的BeanFactory API而不是ApplicationContext)。
  2. 現有配置使用“systemPropertiesMode”和/或“systemPropertiesModeName”屬性。 鼓勵用戶不再使用這些設置,而是通過容器的環境配置屬性源搜索順序; 但是,通過繼續使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM