【问题标题】:Spring XSD's access errorSpring XSD 的访问错误
【发布时间】:2012-09-03 06:14:00
【问题描述】:

我正在尝试运行一个前雇员在我的工作中留下的系统,但我遇到了问题。

如果 XSD 通过远程访问运行:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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-3.0.xsd
                           http://www.springframework.org/schema/aop 
                           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx.xsd">

它给出了一个未找到的异常:

Failed to read schema document 'http://www.springframework.org/schema/context/spring-context-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>.

如果 XSD 通过本地访问运行:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
           http://www.springframework.org/schema/tx
           classpath:org/springframework/transaction/config/spring-tx-3.0.xsd
           http://www.springframework.org/schema/context  
           classpath:org/springframework/context/config/spring-context-3.0.xsd
           http://www.springframework.org/schema/tool
           classpath:org/springframework/beans/factory/xml/spring-tool-3.0.xsd">

它给出了这个例外:

C:\Users\claudiomazur>java -jar c:\temp\fin\c.jar  
0 [AWT-EventQueue-0] INFO support.ClassPathXmlApplicationContext  - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4fa52fdf: startup date [Thu Sep 06  
11:22:59 BRT 2012]; root of context hierarchy  
45 [AWT-EventQueue-0] INFO xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [context.xml]  
Exception in thread "AWT-EventQueue-0" 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 [context.xml]  

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) 

解决这个问题的一些想法?

大大的拥抱!!

【问题讨论】:

  • 什么 xml 解析器在应用程序中使用?
  • 我不知道这个。

标签: java spring exception spring-mvc xsd


【解决方案1】:

Spring XDS 是随 Spring jar 一起定义和交付的!例如spring-context.jar 包含spring-context-3.0.xsd。 (见spring-context.jar/META-INF/spring.schema)

所以检查你的项目中是否有这个 jar。

所以你所说的“远程”并不是真正的远程!而且我从来没有见过你所谓的“本地访问”,所以我会尝试检查为什么“远程”(不是远程)的东西适用于所有 xsd,但 spring-context 除外。


如果它是一个桌面程序,并且您使用包含所有其他已分解 jar 的单个 jar,那么您需要注意来自不同 spring-xxx 的单个 spring.handlersspring.schames 文件的内容.jar 组合在(两个)“hunge”文件中。这样最终这(两个)文件包含所有架构名称和处理程序名称。

【讨论】:

  • 我认为是的,在这个依赖中:code org.springframeworkspring-context3.0.6.RELEASE code
  • @user1618606:我的意思是检查真的!检查此文件是否在您服务器上部署的 WAR 中
  • 是的...它在完整路径上:C:\Users\claudiomazur\.m2\repository\org\springframework\spring-context\3.0.6.RELEASE\spring-context-3.0 .6.RELEASE.jar
  • 在战争中检查它!它必须在 WAR 文件中!
  • 我已禁用所有 Internet 保护,现在它正在访问 xsd... 但现在它给出了最后一个异常:无法找到 XML 模式命名空间的 Spring NamespaceHandler [springframework.org/schema/context] 违规资源:类路径资源 [context.xml]
【解决方案2】:

确实,SPRING XSD 是与罐子一起发货的。

这些 XSD 的存储信息:

  1. 假设在 XML 文件中,我们使用了 beans 命名空间,我们需要查看

    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    
  2. 请检查 META-INF 文件夹中的文件“spring-schemas”spring-beans-4.0.1.RELEASE.jar。 此文件中的示例上下文应为:

    http\://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
    =org/springframework/beans/factory/xml/spring-beans-4.0.xsd
    
    http\://www.springframework.org/schema/beans/spring-beans.xsd 
    =org/springframework/beans/factory/xml/spring-beans-4.0.xsd
    
  3. 这样

         http\://www.springframework.org/schema/beans/spring-beans.xsd  is mapped to      
         org/springframework/beans/factory/xml/spring-beans-4.0.xsd
    

    在你的罐子里

【讨论】:

    【解决方案3】:

    尝试运行 wget http://www.springframework.org/schema/context/spring-context-3.0.xsd

    should be something like: wget http://www.springframework.org/schema/context/spring-context-3.0.xsd
    --2012-09-10 15:56:05--  http://www.springframework.org/schema/context/spring-context-3.0.xsd
    Resolving www.springframework.org... 205.140.197.88
    Connecting to www.springframework.org|205.140.197.88|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 19651 (19K) [text/xml]
    Saving to: “spring-context-3.0.xsd”
    
    100%[=====================================================================>] 19,651      24.6K/s   in 0.8s    
    
    2012-09-10 15:56:06 (24.6 KB/s) - “spring-context-3.0.xsd” saved [19651/19651]
    

    如果您在获取 xsd 架构时遇到问题,则难以处理继承此架构的 xml 文件。

    在第二种情况下,类路径中根本没有任何 spring-*-3.0.xsd 文件。

    【讨论】:

    • @Ralph 是的,你说得对。但所描述的问题行为并不常见。看起来解析器不使用 meta-inf 中定义的内容
    • 对不起,我没有正确阅读您的答案,我希望您建议检查 xsd 文件。
    • 我已禁用所有 Internet 保护,现在它正在访问 xsd... 但现在它给出了最后一个异常:无法找到 XML 模式命名空间的 Spring NamespaceHandler [springframework.org/schema/context] 违规资源:类路径资源 [context.xml]
    • @user1618606 看起来你把 spring-context.jar 没有放在生成的 WAR 文件中的 WEB-INF/lib 目录中。
    • 是的,这绝对是错误的。如果生成的 war 文件不包含 WEB-INF/lib 文件夹,则您的构建过程会中断。在运行构建时检查任何错误或警告。
    猜你喜欢
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 2020-04-10
    • 2014-02-18
    • 1970-01-01
    相关资源
    最近更新 更多