maven spring - 找不到元素“beans”的声明;
我有一个使用 maven 构建的 spring 项目(打包为 jar)(依赖项被复制到单独的目录并添加到类路径)
我想将其作为 java -jar 运行
问题是,当我运行它时,我得到:
Caused作者:org.xml.sax.SAXParseException:cvc-elt.1:找不到声明 元素“豆子”。
发生这种情况是因为 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>
I have a spring project built with the usage of maven (packaged as jar) (dependencies are copied to a separate directory and added to classpath)
I want to run it as java -jar
The problem is that when I run it I get:
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration
of element 'beans'.
It happens because spring.schemas and spring.handlers are located in a few jars i.e.: spring-beans, etc.
Is there any way to solve it, supposing that I don't want to use shade plugin to unpack all dependencies and concatenate the content of spring.schemas and spring.handlers?
I would also like to avoid saving xsd files in my project and changing schemaLocation to point to my location.
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
您可能会遇到此问题
I know 2 situations where you can have this problem
xsi:schemaLocation=" http://www.springframework.org/schema/beans spring-beans-2.5.xsd ..."
我认为 XSD 将是 spring jar 的一部分,所以不应该成为问题。
I think the XSD would be part the spring jar, so shouldn't be issue.
Spring jar 包含 META-INF/spring.handlers 和 META-INF/spring.schemas 文件。为了避免在将依赖项聚合到一个 jar 时覆盖文件,您可以使用 maven Shade 插件:
Spring jars contain META-INF/spring.handlers and META-INF/spring.schemas files. To avoid overwriting the files when aggregating dependencies to one jar you can use maven Shade plugin:
http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer
遇到同样的问题,因为我在代理后面。我在 Tomcat 6 下运行 Spring MVC 应用程序。只需在我的 catalina.bat 文件的 biginning 中添加以下行即可解决我的问题:
Got the same problem because I was behind a proxy. I was running a Spring MVC app under Tomcat 6. Just added the following lines at the biginning of my catalina.bat file and that solved my problem:
我能够通过从远程资源缓存中清除 xsd 文件来解决类似的问题,Window >首选项>一般>网络连接>缓存
I was able to resolve a similar problem by clearing the xsd file from my remote resources cache, Window > Preferences > General > Network Connection > Cache
maven- assembly-plugin 生成的
META-INF/INDEX.LIST
文件也可能是罪魁祸首。原因:Java 错误:“ClassLoader.getResources() 在使用 jar 索引时仅返回 1 个实例”
解决方案:禁用程序集描述符中的索引:
资源:
Spring JIRA SPR-5705
JDK-6957241 ClassLoader.getResources() 在使用 jar 索引时仅返回 1 个实例
META-INF/INDEX.LIST
file generated by the maven-assembly-plugin can also be a culprit.Cause: a Java bug: "ClassLoader.getResources() returns only 1 instance when using jar indexing"
Solution: disable the indexing in the assembly descriptor:
Resources:
Spring JIRA SPR-5705
JDK-6957241 ClassLoader.getResources() returns only 1 instance when using jar indexing
您的 XSD 声明中的
http://
过多。试试这个:(你的是
http://http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
)There's a
http://
too much in your XSD declaration. Try this:(yours was
http://http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
)当我的 XSD url 指向与 jar 文件中定义的 XSD 位置不同的不同位置时,我收到该错误。例如,
spring-beans-3.0.xsd
而不是spring-beans-2.5.xsd
反之亦然。I got that error when my XSD url pointing to different location that is different from XSD location defining in the jar file. For example,
spring-beans-3.0.xsd
instead ofspring-beans-2.5.xsd
vise-versa.您也可以使用 这里解决这个问题
Also you can use advice from here to solve this problem
我遇到了完全相同的问题,我认为这是由两个主要原因引起的:
I had exactly the same problem and I think it is caused by 2 principal reasons: