Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml maven spring-找不到元素';豆子';_Xml_Spring_Maven 2_Schema_Maven - Fatal编程技术网

Xml maven spring-找不到元素';豆子';

Xml maven spring-找不到元素';豆子';,xml,spring,maven-2,schema,maven,Xml,Spring,Maven 2,Schema,Maven,我有一个使用maven(打包为jar)构建的spring项目(依赖项被复制到单独的目录并添加到类路径) 我想把它作为java-jar运行 问题是,当我运行它时,我得到: 原因:org.xml.sax.SAXParseException:cvc elt.1:找不到声明 元素“bean”的名称 之所以发生这种情况,是因为spring.schema和spring.handlers位于几个jar中,如springbean等 假设我不想使用shade插件来解包所有依赖项并连接spring.schemas和

我有一个使用maven(打包为jar)构建的spring项目(依赖项被复制到单独的目录并添加到类路径)

我想把它作为java-jar运行

问题是,当我运行它时,我得到:

原因:org.xml.sax.SAXParseException:cvc elt.1:找不到声明 元素“bean”的名称

之所以发生这种情况,是因为spring.schema和spring.handlers位于几个jar中,如springbean等

假设我不想使用shade插件来解包所有依赖项并连接spring.schemas和spring.handlers的内容,有什么方法可以解决这个问题吗

我还希望避免在项目中保存xsd文件,并将schemaLocation更改为指向我的位置

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

    <camel:camelContext>
        <camel:routeBuilder ref="fakeRouteBuilder"/>
    </camel:camelContext>

    <bean id="fakeRouteBuilder" class="<className>" />


</beans>

您的XSD声明中有一个
http://
太多了。试试这个:

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


(你的是
http://http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

我知道有两种情况会出现此问题

  • 如果您没有internet连接(例如,在代理之后)。在这种情况下,下载XSD,将其复制到XML旁边,并将模式位置更改为
    xsi:schemaLocation=”http://www.springframework.org/schema/beans spring-beans-2.5.xsd…”
  • 如果您有internet连接/仍然存在问题,那是因为您对XSD和jar使用了不同版本的Spring

我认为XSD将是spring jar的一部分,因此不应该出现问题。

当我的XSD url指向与jar文件中定义的XSD位置不同的位置时,我遇到了这个错误。例如,
spring-beans-3.0.xsd
而不是
spring-beans-2.5.xsd
反之亦然。

由于我在代理后面,所以遇到了同样的问题。我在Tomcat6下运行SpringMVC应用程序。刚刚在我的catalina.bat文件的开头添加了以下几行,这就解决了我的问题:

set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyHost=XXXX -Dhttp.proxyPort=YYYYY -Dhttp.proxyUser=ZZZZ -Dhttp.proxyPassword=XXXXXX

您还可以使用来自的建议来解决此问题

Spring JAR包含META-INF/Spring.handlers和META-INF/Spring.schemas文件。为了避免在将依赖项聚合到一个jar时覆盖文件,可以使用maven Shade插件:


我也有同样的问题,我认为这是由两个主要原因造成的:

  • spring安全依赖项和XSD文件引用有不同的版本
  • 如果您使用不同版本的SpringCommonFramework和SpringSecurity,也可能发生这种情况

通过清除远程资源缓存中的xsd文件,我可以解决类似的问题,窗口>首选项>常规>网络连接>缓存

META-INF/INDEX。maven assembly插件生成的列表
文件也可能是罪魁祸首

原因:Java错误:“ClassLoader.getResources()在使用jar索引时只返回1个实例”

解决方案:禁用程序集描述符中的索引:

<indexed>false</indexed>
false
资源:

能否粘贴一个配置spring配置文件?我认为问题可能在那里
检查您的
xsi:schemaLocation
属性。这似乎是不正确的,但这也可能是由于注释中的URL链接造成的。事实上,如果您通过将以前的注释添加为代码块(=选择代码并单击
{}
按钮使其显示为代码块)来编辑您的问题会更好。我的错误,我无意中复制了此内容-在我的上下文中没有“”。我注意到,错误发生在没有互联网连接的情况下。当我将包装更改为war时,问题消失了…只是在本地、无互联网的网络上测试了这个问题。第一点是正确的。只是面对同样的问题,用第一个解决方案解决了!感谢这实际上是正确的答案,spring已经打包了XSD,不会下载它们。这也解决了我在更改项目名称后遇到的类似问题。删除缓存中的所有文件并清理/重建项目修复了该问题。