|
From: <jue...@we...> - 2004-10-19 16:00:12
|
Alternatively, if you don't mind relying on the class loader, you could = register your own ServletContextListener (after ContextLoaderListener), = which takes the ApplicationContext reference from the ServletContext and = stores it in a custom singleton of yours. As long as your singleton class is loaded by the web app class loader, = this shouldn't cause any issues with other web apps; it relies on the = class loader being specific for the web app. Any code within that web = app could then access the Spring ApplicationContext after startup. Of course, the above is not generally recommended, but it should work. Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of Dion Almaer Sent: Tuesday, October 12, 2004 8:25 PM To: spr...@li... Subject: RE: [Springframework-developer] How to getting at an application context 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...]=20 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/acces= s/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/a= pps /ejbtest/src/java/org/springframework/autobuilds/ejbtest/util/context/Con= tex tLoader.java?view=3Dmarkup http://cvs.sourceforge.net/viewcvs.py/springframework/spring/autobuilds/a= pps /ejbtest/src/java/org/springframework/autobuilds/ejbtest/util/context/Con= tex tLoaderListener.java?view=3Dmarkup Regards, Colin Dion Almaer wrote: >Hi guys - > >When I have code in something like a ServletContextListener I can get=20 >access to the application context easily via: > >ApplicationContext appContext =3D >WebApplicationContextUtils.getWebApplicationContext(event.getServletCon >text( >)); > >However, I have a class that is initiated from third party library,=20 >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 > =20 > ------------------------------------------------------- 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 ------------------------------------------------------- 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 |