在我的應用程序中,我需要添加一些基於一些業務邏輯的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 load ApplicationContext global
- 4. Spring ApplicationContext和BeanFactory
- 5. Spring ApplicationContext Bean-wiring
- 6. Spring:@BootstrapWith用於ApplicationContext
- 7. Java Spring ApplicationContext配置
- 8. Spring ApplicationContext Bean範圍
- 9. 沒有XML Spring ApplicationContext
- 10. 如何在Struts2中獲得Spring ApplicationContext?
- 11. Junit 4 Spring - 無法加載ApplicationContext
- 12. 如何在Spring中將兩個ApplicationContext合併到另一箇中?
- 13. 如何從spring applicationContext到達其他項目的資源?
- 14. 在Spring MVC中使用ApplicationContext。
- 15. Spring MVC中的ApplicationContext文件
- 16. 的Java Spring的ApplicationContext以registerBeanDefinition
- 17. Spring:將啓動ApplicationContext的對象注入ApplicationContext
- 18. 無法加載ApplicationContext
- 19. 如何以編程方式在Spring中啓用「annotation-config」ApplicationContext
- 20. 如何使用ApplicationContext從Spring配置中獲取集合
- 21. 如何使用Spring applicationContext從messageSource中檢索消息?
- 22. 如何添加靜態文件使用Spring MVC和Thymeleaf
- 23. ApplicationContext和Spring批處理問題
- 24. Spring 3 applicationContext-security-JDBC.xml有bean:bean不是bean?
- 25. @Autowired Spring NullPointerException ApplicationContext創建後的空Bean
- 26. 使用多個ApplicationContext測試Spring組件
- 27. Spring ApplicationContext佔用了大量的內存
- 28. 在調用bean之前關閉Spring ApplicationContext
- 29. Spring配置XML沒有發現的ApplicationContext
- 30. 在ApplicationContext(Spring)中聲明的DAO類
你能解釋一下你正在嘗試做什麼嗎?豆線將已經發生,所以你將無法注入這些新的屬性... – seanhodges 2012-02-28 10:06:35
是的。當然春天應該重新接線他們。 – meisam 2012-02-28 13:29:59