【问题标题】:XML error when running a spring-GWT app in development mode在开发模式下运行 spring-GWT 应用程序时出现 XML 错误
【发布时间】:2011-07-25 02:08:14
【问题描述】:

我正在使用 eclipse,当我尝试在开发模式下运行我的 spring-GWT 应用程序时,我在解析 applicationContext.xml 文件时收到以下异常:

    Ignored XML validation warning
    org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx-3.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:96)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:380)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
(...)
Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 51 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)

我的 applicationContext.xml 文件是这样开始的:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

(...) 第 51 行 ---> &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;

有人知道发生了什么吗?

【问题讨论】:

    标签: java xml spring gwt xsd


    【解决方案1】:

    检查您的类路径中是否有 spring-tx 依赖项(或任何其他 spring 依赖项),以便它使用您的架构。引用的所有模式都应映射到 spring 依赖项。

    xmlns:tx="http://www.springframework.org/schema/tx"

    检查一下:

    http://www.dashaun.com/2010/03/10/springframework-applicationcontext-woes-unable-to-locate-spring-namespacehandler/

    【讨论】:

    • 你知道,几周前我在 Spring 的 中遇到了类似的问题。我最终做的是从 POM 开始 :( 我认为你的 POM 有问题(我有一个)。也许你的 maven-war-plugin 正确导出所有 .jar 但你的 gwt 插件没有。检查你的指向您的战争目录并构建目录以查看它们是否获得 spring-tx。希望您能找到自己的方式!
    • 你能告诉我具体的检查地点和内容吗?因为我认为为了在开发模式下运行它,不需要创建战争。 (那个,或者我什么地方都看不到!)感谢您的帮助,并对我的新手问题感到抱歉!
    【解决方案2】:

    找到解决方法:

    运行GWT devmode时,启动spring appcontext有问题, 无法找到 tx...xsd。这与定义的类加载器有关 在这个 GWT 的 Devmode 类中,它委托给 systemclassloader (码头覆盖) 见:http://groups.google.com/group/google-web-toolkit/browse_thread/thread/ac495ee6605d21b4

    这仅在定义 spring 中需要的标签时发生 处理事务的@Transactional 注释。 我发现(2天后)解决它的唯一方法是查看堆栈跟踪并找到哪个类的Spring 调用了 xerces(因为它是 xerces 找不到文件)。这是“DefaultDocumentLoader” 这个类在 spring-beans.jar 中。 => 所以我所做的是,我将 spring-tx.jar 中的所有类复制到新的 spring-beans.jar 所以这些类将由同一个类加载器加载 然后我还合并了 META-INF/spring.handlers、spring.schemas、spring.tooling 文件, 现在一切都在我创建的一个新罐子里:spring-beans-tx-3.0.5.RELEASE.jar 这个新 jar 是我项目类路径中的第一个。 在这种情况下它有效!

    【讨论】:

      猜你喜欢
      • 2020-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 2018-02-14
      • 1970-01-01
      相关资源
      最近更新 更多