|
From: Dion A. <di...@al...> - 2004-10-12 18:25:14
|
Colin - Thanks for the great info. I will take a peak and see if I can get it working in a fairly simple way. Once you start working with DI it is too painful to have to leave it behind elsewhere! ;) D -----Original Message----- From: Colin Sampaleanu [mailto:col...@ex...] Sent: Tuesday, October 12, 2004 11:57 AM To: spr...@li... Subject: Re: [Springframework-developer] How to getting at an application context At that point, you're stuck with using some sort of singleton or quasi-singleton, realistically... (which of course is what the servlet context variant is anyways) You can roll your own, or rely on the singleton implementations of BeanFactoryLocator, such as SingletonBeanFactoryLocator or ContextSingletonBeanFactoryLocator. http://www.springframework.org/docs/api/org/springframework/beans/factory/ac cess/SingletonBeanFactoryLocator.html http://www.springframework.org/docs/api/org/springframework/context/access/C ontextSingletonBeanFactoryLocator.html Note that if you do use these, you will want to probably use a slightly modified setup where you use a service layer appcontext, and the web-app context is just a child of that, and still loaded normally via the context loader listener. This loading is easily achieved with a subclass of ContextLoader and ContextLoaderListener, like here: http://cvs.sourceforge.net/viewcvs.py/springframework/spring/autobuilds/apps /ejbtest/src/java/org/springframework/autobuilds/ejbtest/util/context/Contex tLoader.java?view=markup http://cvs.sourceforge.net/viewcvs.py/springframework/spring/autobuilds/apps /ejbtest/src/java/org/springframework/autobuilds/ejbtest/util/context/Contex tLoaderListener.java?view=markup Regards, Colin Dion Almaer wrote: >Hi guys - > >When I have code in something like a ServletContextListener I can get >access to the application context easily via: > >ApplicationContext appContext = >WebApplicationContextUtils.getWebApplicationContext(event.getServletCon >text( >)); > >However, I have a class that is initiated from third party library, >which is loaded from WEB-INF/lib. > >This third party library has nothing to do with the web, so there is no >way to get the ServletContext, and hence the application context. > >Is there anyway that I can get from this loaded class to my nice context? >E.g. can my code look at its ClassLoader and find anything from there? > >Cheers, > >Dion > > ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |