[英]How to get Spring Context
I have a third party library that starting up my aplication, load spring context and save it in private static filed without any acessors. 我有一个第三方库来启动我的应用程序,加载spring上下文并将其保存在没有任何acessor的私有静态文件中。
I need to get this context to my application. 我需要将此上下文添加到我的应用程序中。 Does spring provides some callbacks like afterContextLoaded methods or any other ways how to get it?
spring是否提供了一些回调,例如afterContextLoaded方法或其他任何获取方法?
Reflection is not a solution for me! 反思不是我的解决方案!
Thanks. 谢谢。
you have several ways to archive that: 您可以通过以下几种方式进行归档:
Both of them can be found at http://static.springsource.org/spring/docs/3.0.0.M4/reference/html/ch03s13.html (sorry for the link is not to the latest version) 两者都可以在http://static.springsource.org/spring/docs/3.0.0.M4/reference/html/ch03s13.html上找到(很抱歉,链接不是最新版本)
Just implement ApplicationContextAware in a Spring bean. 只需在Spring bean中实现ApplicationContextAware 。
If you want to access the AppContext on startup, then also implement InitializingBean and put your code in afterPropertiesSet() - the ApplicationContext instance will be populated and ready for use at that time. 如果要在启动时访问AppContext,则还应实现InitializingBean并将代码放入afterPropertiesSet()中 -此时将填充ApplicationContext实例并准备使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.