我對傳統代碼(它是Spring應用程序)進行了分析,發現在Spring上下文中初始化了PropertySourcesPlaceholderConfigurer
和PropertyPlaceholderConfigurer
。我知道在Spring上下文中只應該存在一個PropertyPlaceholderConfigurer
的實例。我的問題是這個規則是否適用於PropertySourcesPlaceholderConfigurer
和PropertyPlaceholderConfigurer
。將它們都放到上下文中是否是錯誤的?PropertySourcesPlaceholderConfigurer和PropertyPlaceholderConfigurer
1
A
回答
2
可以註冊多個屬性配置。但是,如果兩個PlaceholderConfigurer都引用同一組屬性,那麼它的錯誤配置應該避免。
否則,註冊多個PlaceholderConfigurer時,重要的是正確指定bean的順序。所以spring可以爲佔位符解決正確的值。
你可以在這裏找到一個很好的閱讀。
0
PropertySourcesPlaceholderConfigurer是通過採取環境和PropertySource機制也在春3.1提供的優勢更加靈活。
PropertyPlaceholderConfigurer仍然是適當時使用:
- 彈簧上下文模塊不可用(即,一種是使用Spring的BeanFactory的API而不是ApplicationContext中)。
- 現有配置使用「systemPropertiesMode」和/或「systemPropertiesModeName」屬性。鼓勵用戶擺脫使用這些設置,而是通過容器的環境配置屬性源搜索順序;然而,通過繼續使用PropertyPlaceholderConfigurer可以保持功能的確切保存。
PropertySourcesPlaceholderConfigurer此類設計在春季3.1應用程序PropertyPlaceholderConfigurer一般更換。默認情況下,它使用property-placeholder元素來支持spring-context-3.1 XSD,而spring-context版本< = 3.0默認爲PropertyPlaceholderConfigurer,以確保向後兼容。
相關問題
- 1. PropertySourcesPlaceholderConfigurer和SpEL?
- 2. WebSphere和PropertyPlaceholderConfigurer
- 3. PropertyPlaceholderConfigurer和ResourceBundleMessageSource
- 4. propertyPlaceHolderConfigurer和environement可變
- 5. 使用PropertyPlaceholderConfigurer和PropertySource
- 6. 使用PropertySourcesPlaceholderConfigurer
- 7. Spring Jndi上下文和PropertyPlaceholderConfigurer
- 8. 春PropertyPlaceholderConfigurer和MongoDB副本集
- 9. 春3.1 PropertySourcesPlaceholderConfigurer和有條件進口
- 10. 混合PropertySourcesPlaceholderConfigurer和Spring Bean與類型java.util.properties
- 11. Springframework PropertyPlaceholderConfigurer
- 12. PropertySourcesPlaceholderConfigurer的動態位置
- 13. Spring 3.2 PropertySourcesPlaceholderConfigurer with JBoss EAP 6.2
- 14. 春天PropertyPlaceholderConfigurer
- 15. PropertyPlaceholderConfigurer with Hibernate.cfg.xml
- 16. PropertyPlaceholderConfigurer with Tomcat&ContextLoaderListener
- 17. @Value註解和數據庫PropertyPlaceHolderConfigurer
- 18. 春天PropertyPlaceholderConfigurer和內容:財產佔位
- 19. 從資源和PropertyPlaceholderConfigurer的Spring RequestMapping?
- 20. PropertyOverrideConfigurer和PropertyPlaceholderConfigurer有什麼區別?
- 21. 使用@value與PropertyPlaceholderConfigurer
- 22. PropertyPlaceholderConfigurer並依賴上
- 23. Spring自定義PropertyPlaceholderConfigurer
- 24. 如何將環境自動裝入PropertySourcesPlaceholderConfigurer?
- 25. Spring FactoryBean作爲PropertySourcesPlaceholderConfigurer的參考
- 26. 使用佔位符定義PropertySourcesPlaceholderConfigurer
- 27. propertyplaceholderconfigurer類名替代問題
- 28. 無法讓PropertyPlaceholderConfigurer工作
- 29. 自定義PropertyPlaceholderConfigurer不工作
- 30. PropertyPlaceHolderConfigurer不讀Tomcat相關XML
感謝您的回覆。其實我的問題與自動裝配(@Value)在春季Web應用程序(春季MVC)。我有屬性文件和兩個PPC(在問題中提到)在父上下文中。然而,在我的孩子上下文中,我不能使用(@Value)自動裝載屬性,我認爲問題出在這裏。我在子上下文中定義了另一個PPC,但我想重用在父上下文中定義的PPC。在你的引用(第8點)中描述了父子上下文之間的依賴關係。但是,我發現了一個缺陷,描述了爲什麼會發生這種情況https://jira.spring.io/browse/SPR-8994 – mvb13