在我的應用程序中,我需要添加一些基於一些業務邏輯的spring配置文件的內容。我可以使用applicationContextAware類來獲取上下文。我的問題是關於如何在上下文中添加「資源」。我的意思是加載資源並在運行時將它們添加到Context。如何添加到Spring ApplicationContext?
回答
您可以根據您的資源創建新的ApplicationContext,然後將現有的設置爲父上下文。
如果是web應用程序,您需要將新的上下文設置爲spring存儲上下文的上下文變量。
謝謝。只是幾個問題:1.我如何設置父上下文? 2.它是一個Web應用程序,它是使用ContextLoaderListener創建的,而ContextLoaderListener是Context變量使用的?你能給出一行或兩行代碼嗎? – meisam 2012-02-28 10:12:54
聽衆是找出答案的好起點:) 它使用ContextLoader.initWebapplicationcontext(ServletContext)ro啓動一個spring上下文。你需要做的工作是某種相同的。 變量是:WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE 在ContextLoader.createWebApplicationcontext(Servletcontext,ApplicationContext)中顯示了它是如何創建的。 WebApplicationContext有一個setParent()方法。這是很容易的部分:) – wemu 2012-02-28 10:36:21
其實它似乎並沒有webappcontext有一個公共setParent():)也許是困難的部分。也許我錯了,但我不認爲你可以通過複製粘貼彈簧代碼本身獲得功能:)應該有一些暴露的接口或,,,做到這一點。 – meisam 2012-02-28 11:02:59
- 1. 如何將filterclass添加到applicationContext中?
- 2. Spring applicationcontext加載鉤子
- 3. Spring Tool Suite - ApplicationContext未找到
- 4. Spring load ApplicationContext global
- 5. Spring ApplicationContext和BeanFactory
- 6. Spring的ApplicationContext
- 7. Spring ApplicationContext Bean-wiring
- 8. Spring ApplicationContext Bean範圍
- 9. Spring:@BootstrapWith用於ApplicationContext
- 10. 沒有XML Spring ApplicationContext
- 11. Java Spring ApplicationContext配置
- 12. 如何在Struts2中獲得Spring ApplicationContext?
- 13. Spring Maven unitTest applicationContext加載錯誤文件
- 14. Spring框架:無法加載ApplicationContext
- 15. Junit 4 Spring - 無法加載ApplicationContext
- 16. 無法加載Spring的JUnit測試ApplicationContext
- 17. 如何加載的applicationContext
- 18. 如何在Spring中將兩個ApplicationContext合併到另一箇中?
- 19. 如何從spring applicationContext到達其他項目的資源?
- 20. Spring ApplicationContext運行兩次
- 21. 在Spring MVC中使用ApplicationContext。
- 22. 的Java Spring的ApplicationContext以registerBeanDefinition
- 23. Spring MVC中的ApplicationContext文件
- 24. 如何添加jquery和bootstrap添加到spring roo
- 25. 從TestExecutionListener向ApplicationContext添加屬性
- 26. Spring:將啓動ApplicationContext的對象注入ApplicationContext
- 27. 如何在運行時在Spring WebApplicationContext中添加bean實例?
- 28. Spring - 使用從.jar文件添加的applicationContext作爲依賴關係
- 29. 如何使用Spring運行DB單元測試 - 無法加載ApplicationContext
- 30. 無法加載ApplicationContext
你能解釋一下你正在嘗試做什麼嗎?豆線將已經發生,所以你將無法注入這些新的屬性... – seanhodges 2012-02-28 10:06:35
是的。當然春天應該重新接線他們。 – meisam 2012-02-28 13:29:59