Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 创建自定义Web应用程序上下文[SPRING]_Java_Spring - Fatal编程技术网

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

Java 创建自定义Web应用程序上下文[SPRING],java,spring,Java,Spring,我正在构建一个Spring应用程序(它是运行在Geronimo服务器上的单例应用程序,而不是web服务或MVC应用程序)。在加载时,我尝试访问一个内部应用程序上下文(它将管理一组原型bean——基本上是尝试使用分层应用程序上下文来管理所有原型bean,以便干净地关闭这些bean) 我研究了以下各种方法: GenericWebApplicationContext context = new GenericWebApplicationContext(servletContext); context

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

我研究了以下各种方法:

GenericWebApplicationContext context = new GenericWebApplicationContext(servletContext); 
context.setParent(rootApplicationContext); 
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); 
xmlReader.loadBeanDefinitions(new ClassPathResource("ApplicationContext/beans.xml"));
context.refresh();
基本上,创建一个辅助servlet(对我来说不是最好的选择)并访问它们

或使用通用WebApplicationContext(也尝试了所有其他与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)

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

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


因此,请先根据您的适当要求进行搜索。您将获得很多。

人们希望看到您的CustomConetxt.xml tooHi manocha_ak,感谢您的反馈。我会调查的。我在自定义web上下文中搜索主题,没有想到这个用例,不过感谢您指出。非常感谢。谢谢,迪班