简体   繁体   中英

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.

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?

Reflection is not a solution for me!

Thanks.

you have several ways to archive that:

  1. Use ApplicationListerner and ApplicatinEvent
  2. Use ApplicationContextAware

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)

Just implement ApplicationContextAware in a Spring bean.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM