【问题标题】:Creating Custom Web Application Context [SPRING]创建自定义 Web 应用程序上下文 [SPRING]
【发布时间】:2013-12-13 09:06:02
【问题描述】:

我正在构建一个 Spring 应用程序(它是在 Geronimo 服务器上运行的单例应用程序,而不是 Web 服务或 MVC 应用程序)。在加载时,我试图访问一个内部应用程序上下文(它将管理一组原型 bean - 基本上是尝试使用分层应用程序上下文管理所有原型 bean 以彻底关闭这些 bean)。

我研究了以下各种方法:

基本上创建一个辅助 servlet(对我来说似乎不是最好的选择)并访问它们

或使用 GenericWebApplicationContext(也尝试了所有其他与 WebApplicationContext 相关的 API),如下所示:

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

请评论这些方法。有什么建议的方法吗?

n 另外,我还收到如下错误:

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)

谢谢

【问题讨论】:

  • 人们也希望看到您的 CustomConetxt.xml

标签: java spring


【解决方案1】:

在您的异常方面,您实际上并没有正确导入自定义命名空间。 dtd 不存在,或者您没有在 CustomContext.xml 中引用正确的公共位置。

关于你的主要问题,你为什么需要第二个 servlrt 或 WebApplicationContext 本身。你需要管理原型 bean 有很多这样的问题

Spring: How to cleanly terminate prototype-scoped beans?

根据您的适当要求先搜索 SO。你会得到很多。

【讨论】:

  • 您好 manocha_ak,感谢您的反馈。会调查的。我搜索了关于自定义 Web 上下文的主题,没有想到这个用例,不过感谢您的指出。真的很感激。谢谢,Dheeban
猜你喜欢
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 2021-07-28
  • 1970-01-01
  • 2015-11-11
  • 1970-01-01
  • 2011-08-09
  • 1970-01-01
相关资源
最近更新 更多