我正在使用 Maven2 和 Spring 3,当我在 Eclipse 中运行我的项目时一切正常,但是当我使用 assembly:assembly 时,生成的 jar 会抛出以下异常:
Exception in thread "main"
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 4
in XML document from class path resource [beans.xml] is invalid; nested exception
is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of
element 'beans'.
我的 beans 文件看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Beans Here -->
</beans>
这个文件存放在src/main/resources
我的 pom.xml 对 spring 有以下依赖:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.3.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
知道为什么会这样吗?如何修复?
更新:
进一步调查 Google 发现 Spring 和 Maven 与我的 pom.xml 中的以下内容相处得不太好,尽管没有即将到来的解决方案:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
<mainClass>org.robert.xclades.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
最佳答案
我遇到了同样的问题。使用阴影插件有帮助,但我必须按照 http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html 中的描述添加一个转换器。连接 Spring 的处理程序和模式文件。
关于java - Spring 构建问题 - 找不到 Beans 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3353960/