0

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.

nkukhar
  • 1,975
  • 2
  • 18
  • 37

2 Answers2

4

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)

donnior
  • 1,055
  • 1
  • 9
  • 12
1

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.

ianpojman
  • 1,743
  • 1
  • 15
  • 20