|
From: Colin S. <col...@ex...> - 2004-10-12 16:57:59
|
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/access/SingletonBeanFactoryLocator.html http://www.springframework.org/docs/api/org/springframework/context/access/ContextSingletonBeanFactoryLocator.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/ContextLoader.java?view=markup http://cvs.sourceforge.net/viewcvs.py/springframework/spring/autobuilds/apps/ejbtest/src/java/org/springframework/autobuilds/ejbtest/util/context/ContextLoaderListener.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.getServletContext( >)); > >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 > > |