gpt4 book ai didi

java - 从 Java 启动 Spring 应用程序的异常

转载 作者:IT老高 更新时间:2023-10-28 13:53:35 24 4
gpt4 key购买 nike

我能够使用 Maven 编译和启动我的 Spring 项目:

mvn -e clean compile exec:java -Dexec.mainClass=de.fraunhofer.fkie.tet.vmware.manager.Test

但是,当我使用 maven-assembly-plugin(包括 applicationContext.xml)将所有 jar 组装到一个文件中时,我总是得到一个 Exception java 执行期间:

java -cp target/test-jar-with-dependencies.jar:. de.fraunhofer.fkie.tet.vmware.manager.Test

INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Sep 6, 2010 10:37:21 AM org.springframework.util.xml.SimpleSaxErrorHandler warning
WARNING: Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context.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>.
...
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 10 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c:
The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.
...
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c:
The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.

我还尝试将架构定义,即 spring-context.xsd 等直接附加到类路径,但没有任何成功。

less src/main/resources/applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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.xsd">

<context:annotation-config /> <!-- wegen '@PostConstruct' -->
<!--<context:component-scan base-package="de.fraunhofer" /> -->
...
</beans>

最佳答案

Spring 命名空间处理程序使用文件 /META-INF/spring.schemas/META-INF/spring.handlers 解析。因为具有这些名称的文件存在于不同的 Spring jar 中,所以在 maven-assembly-plugin 之后可能只有其中一个保留在目标 jar 中。

也许您可以手动合并这些文件,并以某种方式配置 maven-assembly-plugin 以使用此合并文件覆盖目标 jar 中的文件。

关于java - 从 Java 启动 Spring 应用程序的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3650252/

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