【问题标题】:Spring schemaLocation fails when there is no internet connection没有互联网连接时,Spring schemaLocation 失败
【发布时间】:2010-12-16 07:17:54
【问题描述】:

我正在使用 Spring 并且在 application-context.xml 我有以下定义:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:security="http://www.springframework.org/schema/security"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
   http://www.springframework.org/schema/util 
   http://www.springframework.org/schema/util/spring-util-2.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-2.1.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
   http://www.springframework.org/schema/security
   http://www.springframework.org/schema/security/spring-security-2.0.xsd"
   >

.....

当我的互联网连接中断时,我无法通过 tomcat 或 jetty 运行我的应用程序。

它给出:

[main] WARN  org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document '/spring-beans-2.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)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:2541)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaWarning(XSDHandler.java:2532)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:1836)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:531)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2408)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1753)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:685)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3095)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:921)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    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:423)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
    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:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:115)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:441)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:383)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
    at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:483)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:678)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:553)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:523)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:371)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:332)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:181)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:356)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
2009-11-13 15:31:25,675 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 23 in XML document from class path resource [application-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinit........

有什么建议可以解决吗?

【问题讨论】:

    标签: java xml spring xsd


    【解决方案1】:

    您需要将模式位置添加到您的 bean 定义中,然后它们可以在类路径中找到,而不是通过网络获取。鉴于您的格式问题,我不能 100% 确定您还没有这样做。

    <?xml version="1.0" encoding="UTF-8"?>
    <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"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <!-- empty: the beans we use are in the base class's context. -->
    </beans>
    

    【讨论】:

      【解决方案2】:

      您应该检查spring.handlersspring.schemas 文件是否在类路径中并且具有正确的内容。

      这可以通过ClassLoader.getResource(..) 完成。您可以在运行时环境中使用远程调试器 运行该方法。 Spring Reference B.5. Registering the handler and the schema 中描述了可扩展的 XML 创作设置。

      通常,这些文件应该在 spring jar (springframework.jar/META-INF/) 和可以启动 Spring 的类路径中。

      【讨论】:

      • 嗨,您的解决方案非常复杂;我不明白你是什么意思? jroller.com/marshbourdon/entry/using_spring_2_x_xml,我试过了,但它不起作用。有什么建议 ?在没有互联网连接的情况下运行 web 应用程序并不复杂。我对吗 ?谢谢。
      • Spring 应该开箱即用。您的类路径中的某些内容不正确。我的回答只包含一些分析您的问题的提示。
      【解决方案3】:

      我解决了

      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:util="http://www.springframework.org/schema/util"
             xmlns:context="http://www.springframework.org/schema/context"
             xmlns:aop="http://www.springframework.org/schema/aop"
             xmlns:tx="http://www.springframework.org/schema/tx"
             xmlns:p="http://www.springframework.org/schema/p"
             xmlns:security="http://www.springframework.org/schema/security"
             xsi:schemaLocation="
             http://www.springframework.org/schema/beans 
             http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
             http://www.springframework.org/schema/util 
             http://www.springframework.org/schema/util/spring-util-2.0.xsd
             http://www.springframework.org/schema/context
             classpath:spring-context-2.1.xsd
             http://www.springframework.org/schema/tx
             http://www.springframework.org/schema/tx/spring-tx.xsd
             http://www.springframework.org/schema/aop
             http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
             http://www.springframework.org/schema/security
             http://www.springframework.org/schema/security/spring-security-2.0.xsd"
             >
      

      classpath:spring-context-2.1.xsd 是离线工作模式(没有互联网连接)的关键。我还在 application-context.xml 文件附近(同一目录)复制了spring-context-2.1.xsd

      【讨论】:

      • 适用于可能遇到此问题的 intellij 用户。即使 intellij 无法识别 schemalLocation 中的类路径语法并将其突出显示为错误,这仍然有效。
      • 非常感谢@DaveParoulek - 这个错误让我失望了,但这绝对可以解决问题。
      【解决方案4】:

      如果命名空间配置正确且 XSD 文件位于类路径中,则无需在 schemaLocation URL 中使用 classpath: 协议。

      Spring doc "Registering the handler and the schema" 展示了它应该如何完成。

      在您的情况下,问题可能是您的类路径上的 spring-context jar 不是 2.1。这就是为什么将协议更改为类路径:并将特定的 2.1 XSD 放在类路径中解决了问题。

      据我所知,spring-* jar 中包含的主要 XSD 定义了 2 个模式。一次用版本解析架构 URL,一次不解析。

      作为示例,请参阅 spring-context-3.0.5.RELEASE.jar 中的 spring.schemas 内容的这一部分:

      http\://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd
      http\://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd
      http\://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.0.xsd
      

      这意味着(在 xsi:schemaLocation 中)

      http://www.springframework.org/schema/context/spring-context-2.5.xsd 
      

      将根据

      进行验证
      org/springframework/context/config/spring-context-2.5.xsd 
      

      在类路径中。

      http://www.springframework.org/schema/context/spring-context-3.0.xsd 
      

      http://www.springframework.org/schema/context/spring-context.xsd
      

      将被验证

      org/springframework/context/config/spring-context-3.0.xsd 
      

      在类路径中。

      http://www.springframework.org/schema/context/spring-context-2.1.xsd
      

      未定义,因此 Spring 将使用 schemaLocation 中定义的文字 URL 查找它。

      【讨论】:

      • 对于那些需要总结的人:Spring 在类路径中找不到模式。 Spring 核心 JAR 具有包含在 JAR 中的 schema->filename 映射。如果它无法解决这个问题,它将转到网络。
      • 我已经这样声明了“http:////www.springframework.org/schema/context http:///www.springframework.org/schema/context/spring-context-4.0 .xsd”。我在 Glassfish/domains/domain1/lib 中有 4.0 jar。每当我部署项目时,glassfish 指的是互联网。这个问题是 glassfish-4.0 特有的吗? (添加了更多的“/”用于格式化)
      • 我认为新的“注册处理程序和架构”链接应该在这里:docs.spring.io/spring/docs/current/spring-framework-reference/…
      • @Dirk - 该链接似乎已损坏
      • @Stormcloud,是的,原来的链接似乎又回来了,我建议的那个链接坏了。这是最新的文档链接:docs.spring.io/spring/docs/current/spring-framework-reference/…
      【解决方案5】:

      这样的事情对我有用。

      xsi:schemaLocation=
      "http://www.springframework.org/schema/beans 
                   classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context 
                   classpath:org/springframework/beans/factory/xml/spring-context-3.0.xsd"
      

      【讨论】:

      • 是的,这是因为 xsd 被打包在 spring jar 中。因此,当您可以使用 jar 内的 xsd 时,无需查看 springframework.com :)
      • 这个解决方案对我有用,因为我在一个罐子里有弹簧依赖项,我的意思是作为一个外部罐子,并且没有互联网失败,你的解决方案对我来说非常有效,非常感谢上帝保佑。
      • @godlikeNoob 我试过这个,但它再次给出错误“cvc-elt.1:找不到元素'beans'的声明。”
      【解决方案6】:

      问题在于您在应用程序中使用的 JAR 文件。

      我所做的工作是进入与我正在使用的版本匹配的 SPRING-CORE、SPRING-BEANS、SPRING-CONTEXT、SPRING-TX 的 JAR。在 META-INF 文件夹中,我连接了这些 JAR 中的所有 spring.handlers 和 spring.schemas。

      我用一块石头杀死了两只鸟,我解决了模式的问题,所以这在离线模式下也能正常工作。

      附:我尝试了 SHADE 和转换器的 maven 插件,但是没有用。

      【讨论】:

      • 你是怎么解决这个问题的,你能帮我理解一下吗?我有需要。
      【解决方案7】:

      我们解决了这个问题:

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      factory.setValidating(false); // This avoid to search schema online
      factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
      factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "TransactionMessage_v1.0.xsd");
      

      请注意,我们的应用程序是 Java 独立离线应用程序。

      【讨论】:

        【解决方案8】:

        如果您使用 Eclipse 进行开发,那么如果您为 Eclipse 安装 STS 插件会有所帮助[来自特定版本的 eclipse 的市场。

        现在,当您尝试在项目内的文件夹(通常是资源)中创建新配置文件时,选项将具有“Spring 文件夹”,您可以选择“Spring Bean 定义文件”选项 Spring > Spring Bean 配置文件。

        选择此选项后,当您按照步骤操作时,它会要求您选择命名空间和特定版本:

        因此可以消除 jar 或旧版本不存在的可能性。

        也会发布图片,但我的声誉很低.. :(

        【讨论】:

          【解决方案9】:

          如果有人通过与我相同的根到达这里 - 我遇到了这个问题,因为我正在构建一个包含所有依赖项的单个 JAR,包括 Spring JAR。因此,Spring JAR 的某些 META-INF 目录中的 spring.schemas 文件被覆盖。

          我在这里找到了建议的解决方案:How to create spring-based executable jar with maven?

          【讨论】:

            【解决方案10】:

            今天遇到了类似的问题。就我而言,除了 springframework.org 出现中断之外,罪魁祸首是 shade 插件。以下 sn-p 清除了一切:

            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
               <resource>META-INF/spring.schemas</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                <resource>META-INF/spring.handlers</resource>
            </transformer>
            

            某人

            【讨论】:

            • 上面的sn-p需要在哪里添加?
            【解决方案11】:

            我想为这次讨论添加一些额外的内容。在 Windows 操作系统中,我观察到,当包含架构的 jar 文件存储在路径包含空格字符的目录中时,例如下面的示例

            "c:\Program Files\myApp\spring-beans-4.0.2.RELEASE.jar"
            

            当您开发一些也应该离线工作的独立应用程序时,以以下方式指定架构位置 URL 是不够的

            <beans
             xsi:schemaLocation="
               http://www.springframework.org/schema/beans org/springframework/beans/factory/xml/spring-beans-2.0.xsd"
                />
            

            我了解到这种架构位置 URL 解析的结果是一个具有如下路径的文件

            "c:\Program%20Files\myApp\spring-beans-4.0.2.RELEASE.jar"
            

            当我从路径上不包含空格字符的其他目录启动我的应用程序时,架构位置解析工作正常。也许有人遇到过类似的问题?尽管如此,我发现类路径协议在我的情况下工作正常

            <beans
             xsi:schemaLocation="
               http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-2.0.xsd"
                />
            

            【讨论】:

              【解决方案12】:

              删除您最近在 web-inf ->lib 中添加的 jars。例如 jstl 罐子。

              【讨论】:

                【解决方案13】:

                我遇到了这个问题。对于后代,我的例外是:

                org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 117;
                schema_reference.4: Failed to read schema document
                'http://www.springframework.org/schema/beans/spring-beans-4.2.xsd'
                

                当我意识到我的 Maven pom.xml 中指定的 spring-beans 的版本是 4.1.x 时,我解决了这个问题,这意味着在类路径中找不到特定的 .xsd

                这被掩盖了很长时间,因为我通常在线,所以我认为离线已经“破坏”了构建。但这确实与它无关。更新我的pom.xml 以指定spring-beans 的正确版本,即4.2.x,修复它。

                【讨论】:

                  【解决方案14】:

                  查找类路径

                  如果您使用的是 Eclipse,请单击相应的 jar 文件。转到 ->META-INF-> 打开文件 spring.schemas

                  你会看到类似下面的线条。

                  http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.1.xsd

                  在 = 之后复制并配置如下所示的 bean。

                  <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:rabbit="http://www.springframework.org/schema/rabbit" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/rabbit classpath:org/springframework/amqp/rabbit/config/spring-rabbit-1.1.xsd http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.1.xsd http://www.springframework.org/schema/context classpath:org/springframework/context/config/spring-context-3.1.xsd http://www.springframework.org/schema/util classpath:org/springframework/beans/factory/xml/spring-util-3.1.xsd">

                  【讨论】:

                  • 我在 xml springframework.org/schema/rabbit classpath:org/springframework/amqp/rabbit/config/spring-rabbit-1.6.xsd 中做了这个更改,但它说读取失败架构文档“类路径:org/springframework/amqp/rabbit/config/spring-rabbit-1.6.xsd”?任何建议
                  【解决方案15】:

                  当我使用 spring-context 版本 4.0.6 和 spring-security 版本 4.1.0。

                  在我的 pom 和 security xml 中将 spring-security 版本更改为 4.0.4(因为 spring-security 的 4.0.6 不可用)-->schemaLocation 时,它会在没有互联网的情况下编译。

                  也就是说你也可以通过以下方式解决这个问题:

                  • 将 spring-security 更改为旧版本或相同版本 弹簧上下文。

                  • 将 spring-context 更改为更新或相同的版本 弹簧安全。

                  (以任何方式使 spring-context 更新或与 spring-security 版本相同)

                  【讨论】:

                    【解决方案16】:

                    我也遇到过类似的问题。就我而言,我的分辨率完全不同。这是我的 spring 上下文 xml 文件:

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

                    我没有指定任何 xsd 版本,因为我希望 spring 在 spring 依赖项中使用最新的 xsd 版本。我的应用程序使用的 spring 版本是 spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE ,当我将应用程序组装到 jar 中时,所有 spring 依赖项都存在于我的类路径中。但是,在我的 spring 应用程序上下文启动期间,我收到了以下错误:

                    org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.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>.
                    

                    经过一番艰难的故障排除后,我发现问题是由于我的 jar 文件的 META-INF 文件夹中的 index.list 造成的。使用 index.list 文件,无法找到 spring 命名空间处理程序以正确解析 spring 应用程序上下文 xml。你可以阅读更多关于这个春季问题SPR-5705

                    通过从我的 ma​​ven-jar-plugin 中删除索引,我设法解决了这个问题。希望这将为遇到同样问题的人节省一些时间。

                    【讨论】:

                      【解决方案17】:

                      只需确保相关的 spring jar 文件位于您的运行时类路径中。在我的情况下,我们从运行时类路径中丢失了 spring-tx-4.3.4.RELEASE.jar。添加这个jar后,问题就解决了。

                      【讨论】:

                        【解决方案18】:

                        如果您的平台没有互联网连接并且您使用 Eclipse,请按照以下步骤操作(它解决了我的问题)

                        1. 找到确切的 xsd 文件(您可以从它们的 jar 中解压缩这些文件。例如 spring-beans-x.y.z.RELEASE.jar 中的 spring-beans-x.y.xsd)
                        2. 将这些 xsd 文件添加到 Eclipse XML 目录。 (首选项->XML->XML 目录,添加文件)
                        3. 将这些文件位置添加到配置文件中。 (小心,写出文件的确切版本)

                        例子:

                        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-x.y.xsd"

                        【讨论】:

                          猜你喜欢
                          • 1970-01-01
                          • 1970-01-01
                          • 1970-01-01
                          • 2015-06-03
                          • 1970-01-01
                          • 1970-01-01
                          • 2014-10-10
                          • 1970-01-01
                          • 2015-09-12
                          相关资源
                          最近更新 更多