简体   繁体   English

创建自定义Web应用程序上下文[SPRING]

[英]Creating Custom Web Application Context [SPRING]

I am building a Spring application (which is a singleton application running on Geronimo server , not a web service or MVC application). 我正在构建一个Spring应用程序(它是在Geronimo服务器上运行的单例应用程序,而不是Web服务或MVC应用程序)。 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). 在负载方面,我试图访问一个内部应用程序上下文(它将管理一组原型Bean-基本上是尝试使用分层应用程序上下文来管理所有原型Bean,以彻底关闭这些Bean)。

I looked at various approaches as below: 我查看了以下各种方法:

Basically creating a secondary servlet (does not look like the best option to me) and accessing them 基本上创建一个辅助servlet(对我来说似乎不是最好的选择)并访问它们

Or using a GenericWebApplicationContext (also tried all other WebApplicationContext related APIs) as below: 或使用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();

Please comment on the approaches. 请评论这些方法。 Is there any suggested approach ? 有什么建议的方法吗?

n addition, I also got the following error: 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)

Thanks 谢谢

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. dtd不存在,或者您没有在CustomContext.xml中引用正确的公共位置。

And on the main question of yours, why do you need second servlrt or WebApplicationContext itself. 关于您的主要问题,您为什么需要第二个服务或WebApplicationContext本身。 you need to manage prototype beans There are many questions onto that like this 您需要管理原型bean像这样有很多问题

Spring: How to cleanly terminate prototype-scoped beans? 春季:如何彻底终止原型范围内的bean?

Search SO first with proper requirement of yours. 首先按照您的要求进行搜索。 You will get many. 你会得到很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM