1

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 ?

n addition, I also got the following error:

2013-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

Marius
  • 15,148
  • 9
  • 56
  • 76
dheeban
  • 65
  • 1
  • 6

1 Answers1

0

On your exception front you are not importing the custom namespace correctly actually. Either the dtd is not there or you are not referring to right public location in CustomContext.xml.

And on the main question of yours, why do you need second servlrt or WebApplicationContext itself. you need to manage prototype beans There are many questions onto that like this

Spring: How to cleanly terminate prototype-scoped beans?

Search SO first with proper requirement of yours. You will get many.

Community
  • 1
  • 1
manocha_ak
  • 904
  • 7
  • 19
  • Hi manocha_ak, Thanks for the feedback. Will look into it. I searched for topics on custom web context, did not think of this use case, thanks for pointing out though. Really appreciate it. Thanks, Dheeban – dheeban Dec 13 '13 at 22:14