Saturday 3 October 2009

Sproing: Spring static ApplicationContext access

It is often useful to gain access to the ApplicationContext object in order to locate existing beans. Sproing provides a ApplicationContextProvider class that can be used anywhere in a spring application to access the application context like so:


ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();


If you have used Sproing to start the application and/or load Spring, you will automatically have access to this class. If you want to use this feature of Sproing in a web application, all you need to do is declare the ApplicationContextProvider as a spring bean in your spring xml file ie


<bean id="applicationContextProvider" class="uk.org.sith.sproing.spring.ApplicationContextProvider"/>


Sproing version 0.3.1alpha is available now from Sith Open Source

No comments: