我有一个单元测试中使用的测试XML文件,该文件引用src/main/resources
中的模式。当我在IntelliJ中运行测试时,src/main/resources
中的架构已成功添加到类路径中:
DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver - Found XML schema [http://www.meanwhileinhell.com/mih/schemas/spring/core-admin.xsd] in classpath: com/meanwhileinhell/mih/admin/core/spring/jbox-core-admin.xsd
但是,当我使用Gradle在命令行上运行时,它找不到XSD,并且出现了SAXException:
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document
'http://www.meanwhileinhell.com/mih/schemas/spring/core-admin.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>.
java.lang.IllegalStateException: Failed to load ApplicationContext
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 'service-info'.
-
src
test
resources
- test-service-info.xml
test-service-info.xml
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.meanwhileinhell.com/mih/schemas/spring/core-admin http://www.meanwhileinhell.com/mih/schemas/spring/core-admin.xsd
<mih:restlet-application id="testApplicationId"
name="testApplication" matchingMode="2"> <<< Line 16, column 49 is after the `>`
-
src
main
resources
- mih-core-admin.xsd
mih-core-admin.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://www.meanwhileinhell.com/mih/schemas/spring/core-admin"
xmlns:core_admin="http://www.meanwhileinhell.com/mih/schemas/spring/core-admin">
这不是mih-core-admin.xsd
和core-admin
之间的命名问题。另外,当我将相同的xsd添加到src/test/resources
和src/test/resources/spring
时,仍然找不到它。
IJ和CLI的Gradle版本:4.10.2
我尝试将以下内容添加到项目的build.gradle
中,但在类路径上仍然没有文件:
sourceSets {
test {
resources {
srcDirs = ['src/test/resources', 'src/main/resources/']
}
}
}
和...
sourceSets {
test {
resources {
srcDir 'src/test/resources'
include 'src/main/resources/mih-core-admin.xsd'
}
}
}
和...
sourceSets {
test {
output.resourcesDir = "build/resources/main"
}
}
和...
sourceSets.main.compileClasspath
在上述示例中,还尝试使用build/resources/main
而不是src/main/resources
。