gpt4 book ai didi

java - 运行测试时无法使用 spring-boot-starter-web 依赖项

转载 作者:行者123 更新时间:2023-12-02 05:02:42 25 4
gpt4 key购买 nike

我有使用 gradle(web,common,batch) 的多模块项目

项目运行良好

但是,当我尝试从批处理模块的测试文件夹中运行 junit 时,当 Spring 出现时,我得到了这个:

Caused by: java.lang.NoClassDefFoundError: org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverter

我从批处理模块检查了依赖关系树:

<batch>gradle -q dependencies --configuration testRuntime

我在尝试导入 spring-boot-start-web 时看到按钮失败

.....
| | +--- com.caucho:resin-hessian:4.0.23
| | +--- org.springframework:spring-jdbc:3.1.0.RELEASE -> 4.1.4.RELEASE (*)
| | +--- com.adobe.blazeds:blazeds-common:3.2.0.3978
| | +--- com.adobe.blazeds:blazeds-proxy:3.2.0.3978
| | +--- org.codehaus.jackson:jackson-core-asl:1.9.2
| | +--- org.codehaus.jackson:jackson-mapper-asl:1.9.2 (*)
| | \--- org.mockito:mockito-all:1.9.5
| +--- com.mycompany.services.configuration:ConfigurationManager:2.0.8 (*)
| +--- com.caucho:resin-hessian:4.0.23
| +--- mysql:mysql-connector-java:5.1.34
| \--- javax.inject:javax.inject:1
+--- org.springframework.boot:spring-boot-starter-test:1.2.1.RELEASE
| +--- junit:junit:4.12
| | \--- org.hamcrest:hamcrest-core:1.3
| +--- org.mockito:mockito-core:1.10.8
| | +--- org.hamcrest:hamcrest-core:1.1 -> 1.3
| | \--- org.objenesis:objenesis:2.1
| +--- org.hamcrest:hamcrest-core:1.3
| +--- org.hamcrest:hamcrest-library:1.3
| | \--- org.hamcrest:hamcrest-core:1.3
| +--- org.springframework:spring-core:4.1.4.RELEASE (*)
| \--- org.springframework:spring-test:4.1.4.RELEASE
| \--- org.springframework:spring-core:4.1.4.RELEASE (*)
+--- org.springframework.batch:spring-batch-test:3.0.2.RELEASE
| +--- junit:junit:4.11 -> 4.12 (*)
| +--- org.hamcrest:hamcrest-all:1.3
| \--- org.springframework.batch:spring-batch-core:3.0.2.RELEASE (*)
\--- org.springframework.boot:spring-boot-starter-web: FAILED

这是我在批处理模块上的 build.gradle:

buildscript {
repositories {
maven { url "http://repo.spring.io/libs-release" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$project.ext.springBootVersion")

}
}

description = 'batch'

dependencies {
compile("org.springframework.boot:spring-boot-starter-batch:$project.ext.springBootVersion")
testRuntime("org.springframework.batch:spring-batch-test:$project.ext.springBatchVersion") {
exclude(module: 'spring-test')
exclude(module: 'spring-jdbc')
exclude(module: 'commons-io')
exclude(module: 'commons-collections')
}

/* compile ('org.springframework.integration:spring-integration-core:4.1.2.RELEASE')*/
compile project(":common")
testRuntime("org.springframework.boot:spring-boot-starter-web")

}

知道出了什么问题吗?

谢谢。

最佳答案

您要么需要在声明依赖项时提供版本号,要么需要应用 Spring Boot 插件(您已将该插件声明为构建脚本依赖项,但似乎并未应用它) .

当应用 Spring Boot 插件时,它会自动将 spring-boot-starter-web 的版本设置为与插件相同的版本。你可以看到一个list of all the versions该插件可以在文档中为您设置。

关于java - 运行测试时无法使用 spring-boot-starter-web 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28093473/

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