gpt4 book ai didi

xml - maven spring - 找不到元素 'beans'的声明

转载 作者:IT老高 更新时间:2023-10-28 13:55:49 27 4
gpt4 key购买 nike

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

我想以 java -jar 的形式运行它

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

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

这是因为 spring.schemas 和 spring.handlers 位于几个 jar 中,即:spring-beans 等。

有什么办法可以解决,假设我不想用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,将其复制到 XML 旁边,并将模式位置更改为 xsi:schemaLocation="http://www.springframework.org/schema/beans spring-beans-2.5.xsd 。 ..”
  • 如果您有互联网连接/仍然有问题,那是因为您为 XSD 和 jar 使用了不同版本的 Spring。

关于xml - maven spring - 找不到元素 'beans'的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4972034/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com