【问题标题】:Unable to locate Spring NamespaceHandler for XML schema namespace [http://camel.apache.org/schema/spring] through eclipse无法通过 Eclipse 找到 XML 模式命名空间 [http://camel.apache.org/schema/spring] 的 Spring NamespaceHandler
【发布时间】:2014-03-28 00:17:10
【问题描述】:

我已经阅读了有关此问题的所有其他 SO 帖子,但没有一篇涉及骆驼和 applicationContext.xml。一个多星期以来,我一直在努力解决这个问题,因此我束手无策。

问题:我可以通过 Tomcat 6 运行我的 GWT 应用程序。但是,一旦我尝试使用 Run As Web Application 通过 Eclipse 执行它,我就会在控制台收到以下输出:

[WARN] Server class 'org.springframework.web.context.ContextLoaderListener' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/company/m2/repo/org/springframework/spring-web/2.5.6/spring-web-2.5.6.jar' to the web app classpath for this session
[WARN] Server resource 'log4j.properties' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/company/projects/svn/reco/services/portal/trunk/portal-trunk/portal-um/src/test/resources/' to the web app classpath for this session
[WARN] Server class 'com.company.session.PortalSessionListener' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/company/m2/repo/serviceUtil/serviceUtil/trunk/serviceUtil-trunk.jar' to the web app classpath for this session
[WARN] Server class 'org.springframework.context.ApplicationContextException' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/company/m2/repo/org/springframework/spring-context/2.5.6/spring-context-2.5.6.jar' to the web app classpath for this session
[WARN] Server class 'org.springframework.beans.FatalBeanException' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/company/m2/repo/org/springframework/spring-beans/2.5.6/spring-beans-2.5.6.jar' to the web app classpath for this session
[WARN] Server class 'org.springframework.core.NestedRuntimeException' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/company/m2/repo/org/springframework/spring-core/2.5.6/spring-core-2.5.6.jar' to the web app classpath for this session
[WARN] Server class 'org.apache.commons.collections.map.CaseInsensitiveMap' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/company/m2/repo/com/google/gwt/gwt-dev/2.4.0/gwt-dev-2.4.0.jar' to the web app classpath for this session
Starting Jetty on port 8888
   [WARN] Failed startup of context com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload@192232de{/,C:\company\projects\svn\reco\services\portal\trunk\portal-trunk\portal-entrypoint\target\portal-entrypoint-trunk}
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://camel.apache.org/schema/spring]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]

  at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
  at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
  at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1294)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
  at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
  at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
  at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
  at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
  at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
  at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)
  at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
  at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
  at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
  at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
  at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
  at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
  at org.mortbay.jetty.Server.doStart(Server.java:222)
  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
  at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
  at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
  at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
  at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
  at com.google.gwt.dev.DevMode.main(DevMode.java:311)

我不知道该怎么做,我的任何同事也不知道。我也不知道在这篇文章中要包含哪些其他信息。

【问题讨论】:

    标签: java xml eclipse spring gwt


    【解决方案1】:

    看起来您的 Eclipse“作为 Web 应用程序运行”设置正在使用 Jetty 而不是 tomcat,并且不知何故会导致不同的类路径配置。从外观上看,您可能会错过码头上的一些罐子(与骆驼有关的)。

    如果您不使用 maven 之类的依赖管理,通常会发生这种情况,即:您必须有意识地管理在哪个环境中您的类路径中包含/不包含什么路径。

    更简单的方法是在生产和开发中使用相同的容器,并通过在 maven pom 中声明来确保您需要的其他 jar 包含在 WEB-INF/lib 中。

    【讨论】:

    • 我正在使用 Maven。我真的不知道您所说的“对生产和开发使用相同的容器”是什么意思而且我需要的一切都应该在 pom 中声明,我团队中的其他开发人员都可以正常工作,所以它必须是我的设置,而不是 pom。
    • 顺便说一句,我认为camel.apache.org/schema/spring 不是来自spring-camel jar,而是真正的camel jar。你有没有仔细检查过你在类路径上真的有这个吗?
    【解决方案2】:

    在开发模式下从 Eclipse 运行 GWT 应用程序时,它使用调试配置中定义的类路径。这是您用于编译的代码的构建路径以及您手动添加的任何其他 jar 或文件夹。此外,由于它是一个网络应用程序,它还将使用 WEB-INF/lib 文件夹中的任何 jars。

    当你收到消息时

    [WARN] 服务器类 'org.springframework.web.context.ContextLoaderListener' 不能 在 Web 应用程序中找到,但在系统类路径中找到 [WARN] 添加类路径条目 '文件:/C:/company/m2/repo/org/springframework/spring-web/2.5.6/spring-web-2.5.6.jar' 到此会话的 Web 应用类路径

    这意味着代码无法在 WEB-INF/lib 文件夹中找到,但在您的调试配置定义的类路径中找到。 GWT 开发模式会将此 jar 添加到您正在运行的 Web 应用程序类路径中。

    通常这一切都可以正常工作,但如果您的代码依赖于使用某种类路径搜索机制动态查找的类,则此过程不起作用。这就是这里发生的事情 - 命名空间处理程序和关联的架构将在骆驼罐中,但这不在您的类路径中。

    答案很简单——只需将包含命名空间处理程序的 jar 添加到 WEB-INF/lib 文件夹即可。

    我经常遇到这个问题 - 主要是 Spring,还有 RSS 库 Rome。我的项目是使用 Maven 构建的,为了管理它,我使用 devmode 配置文件配置了 Maven,该配置文件包括我需要的所有运行时依赖项,目标是将我的所有依赖项复制到 WEB-INF/lib 文件夹中。这意味着我可以从 Maven 管理我的所有依赖项 - 在共享项目时很有用。

    【讨论】:

    • camel-spring-2.0-M3.jar 在WEB-INF/lib文件夹里:(
    • 另外,我似乎有几个 WEB-INF 文件夹。有一个位于portal-entrypoint/src/main/webapp/WEB-INF,但其中没有 lib 文件夹。然后在portal-entrypoint/target/ROOT/WEB-INF 有一个,该文件夹包含一个 deploy 和 lib 文件夹以及大量 jar。最后在portal-entrypoint/target/portal-entrypoint-trunk/WEB-INF 有一个,但只有类和部署文件夹。没有 lib 文件夹。所有这些位置都包含一个applicationContext.xml 和一个web.xml 文件。
    • GWT Eclipse 插件使用Project Properties > Google > Web Application 中配置的war 目录。您应该会发现它在开发模式下使用 WEB-INF/lib 文件夹。这就是您需要放置包含命名空间处理程序和模式的 jar 的地方。使用 Maven 可能会有点复杂,请参阅 mojo.codehaus.org/gwt-maven-plugin/user-guide/war-folder.html
    • 如果您还没有看过它,这可能很有用stackoverflow.com/questions/7442391/…
    【解决方案3】:

    忘记更新我的解决方案。事实证明,在我的Google > Web Application 下的项目属性中,War Directory: 没有正确指向我的 WAR 目录。我将其更改为指向target/ROOT,现在一切正常。

    【讨论】:

      猜你喜欢
      • 2010-12-03
      • 2019-01-27
      • 2011-01-10
      • 2018-05-16
      • 2013-10-04
      • 2015-02-25
      相关资源
      最近更新 更多