java Spring XSD 的访问错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12350673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:31:42  来源:igfitidea点击:

Spring XSD's access error

javaspringexceptionspring-mvcxsd

提问by claudioivp

I'm trying to run a system left by an ex-employee here in my job, but I'm having problems to do it.

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

If the XSD runs by remote access:

如果 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">

It gives an not found exception:

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

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>.

And if the XSD runs by local access:

如果 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">

It gives this exception:

它给出了这个例外:

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) 

Some idea to solve this problem?

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

Big hug!!

大大的拥抱!!

回答by Ralph

The Spring XDSs are defined and shipped with the Spring jars! For Example the spring-context.jarcontains the spring-context-3.0.xsd. (see spring-context.jar/META-INF/spring.schema)

Spring XDS 是随 Spring jar 定义和提供的!例如spring-context.jar包含spring-context-3.0.xsd. (见spring-context.jar/META-INF/spring.schema)

So check that you have this jar in your project.

因此,请检查您的项目中是否有这个 jar。

So what you called "remote" is not really remote! And I have never see what you called "local access", so I would try to check why the "remote" (that is not remote) stuff works for all xsds but the spring-context.

所以你所说的“远程”并不是真正的远程!而且我从来没有看到你所谓的“本地访问”,所以我会尝试检查为什么“远程”(不是远程)的东西适用于所有 xsd,但弹簧上下文。



If it is a desktop program and you use a single jar that contains all the other exploded jars, then you need a to take care that the content of the single spring.handlersand spring.schamesfiles from the different spring-xxx.jar is COMBINED in (two) "hunge" files. So that in the end this (two) files contains all the schema names and handler names.

如果它是一个桌面程序,并且您使用一个包含所有其他爆炸 jar 的单个 jar,那么您需要注意单个spring.handlersspring.schames来自不同 spring-xxx.jar 的文件的内容在(两个)中合并”饥饿”文件。所以最终这(两个)文件包含所有模式名称和处理程序名称。

回答by hemantvsn

Its true that the SPRING XSD's are shipped along with the jars.

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

The information where these XSD's are stored :

存储这些 XSD 的信息:

  1. Lets say in the XML file, we have used beans namespace and we need to look into

    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    
  2. Please check the file "spring-schemas" spring-beans-4.0.1.RELEASE.jar in META-INF folder. Sample context from this file should be:

    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. Thus

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

    in your jar

  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
    

    在你的罐子里

回答by user1516873

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

尝试运行 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]

If you have a problem with getting xsd schema, it makes difficult to work with xml files inherited this schema.

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

In second case you simply don't have in classpath any of spring-*-3.0.xsd files.

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