• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating Hierarchical Web Application Context in Spring

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I am building a Spring application (which is a singleton application running on Geronimo server , not a web service or MVC application). On its load, I am trying to access a internal application context (which would manage a set of prototype beans - basically trying to manage all prototype beans using a hierarchical application context for clean shutdown of these beans).

I looked at various approaches as below:

Basically creating a secondary servlet (does not look like the best option to me) and accessing them

Or using a GenericWebApplicationContext (also tried all other WebApplicationContext related APIs) as below:

GenericWebApplicationContext context = new GenericWebApplicationContext(servletContext);
context.setParent(rootApplicationContext);
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
xmlReader.loadBeanDefinitions(new ClassPathResource("ApplicationContext/beans.xml"));
context.refresh();

Please comment on the approaches. Is there any suggested approach ?

In addition, I also got the following error:

013-12-13 00:44:04,877 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ZKWatcherImpl' defined in URL [bundleresource://382.fwk1189431013/com/ebay/traffic/email/aggregate/watcher/ZKWatcherImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ebay.traffic.email.aggregate.watcher.ZKWatcherImpl]: Constructor threw exception;
nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context] Offending resource: class path resource [CustomContext.xml]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)

Thanks,
Dheeban

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you needing to shut down exactly? These beans are holding on to expensive resources? You could just clean it up when you are done.




You could also do similar with XML if you prefer. The old way before providers was to use method injection for getting prototype beans injected in singletons.
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic