简体   繁体   English

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

[英]Cant use spring-boot-starter-web dependecies when running tests

I have multi-module project using gradle(web,common,batch) 我有使用gradle(web,common,batch)的多模块项目

The project is running fine 该项目运行良好

however when I am trying to run junit from test folder of batch module when the spring comes up I get this: 但是,当我试图从弹簧的批处理模块的测试文件夹中运行junit时,我得到了:

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

I checked dependency tree from the batch module: 我从批处理模块检查了依赖树:

<batch>gradle -q dependencies --configuration testRuntime

And I see in the buttom FAILED while trying to import spring-boot-start-web 我在尝试导入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

this is my build.gradle on the batch module: 这是我在批处理模块上的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")

}

Any idea what's wrong ? 知道有什么问题吗?

Thank you. 谢谢。

A couple of options, change: 几个选择,更改:

testRuntime("org.springframework.boot:spring-boot-starter-web")

to: 至:

compile("org.springframework.boot:spring-boot-starter-web")

Also, my Spring Boot build.gradle file does not use the :$project.ext.springBatchVersion variable. 另外,我的Spring Boot build.gradle文件不使用:$project.ext.springBatchVersion变量。 It seems to set the variables just fine - for example, here is my (condensed) example build.gradle file.: 似乎将变量设置得很好-例如,这是我的(压缩的)示例build.gradle文件。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    testCompile("junit:junit")
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

You either need to provide a version number when you're declaring the dependency or you need to apply the Spring Boot plugin (you've declared the plugin as a build script dependency, but don't appear to have applied it). 您在声明依赖项时需要提供版本号,或者需要应用Spring Boot插件(您已经将该插件声明为构建脚本依赖项,但似乎没有应用)。

When the Spring Boot plugin is applied it'll automatically set the version of spring-boot-starter-web to the same version as the plugin. 应用Spring Boot插件后,它将自动将spring-boot-starter-web的版本设置为与插件相同的版本。 You can see a list of all the versions that the plugin can set for you in the documentation. 您可以在文档中看到该插件可以为您设置的所有版本列表

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加spring-boot-starter-web时Spring Boot App启动时出错 - Error on Spring Boot App Startup when adding spring-boot-starter-web 在没有 spring-boot-starter-web 的情况下配置 Spring Security AuthenticationManager - Configure Spring Security AuthenticationManager without spring-boot-starter-web 结合 ObjectDB 使用 Spring-Boot-Starter-Web - Using Spring-Boot-Starter-Web in combination with ObjectDB 使用 spring-boot-starter-web “找不到可接受的表示” - "Could not find acceptable representation" using spring-boot-starter-web spring-boot-starter-web和spring-boot-starter-web-services以及spring-boot-starter-jersey之间的区别 - Difference between spring-boot-starter-web and spring-boot-starter-web-services and spring-boot-starter-jersey spring-boot-starter-web 和 spring-boot-starter-webflux 不能一起工作吗? - Don't spring-boot-starter-web and spring-boot-starter-webflux work together? Spring 即使使用 spring-boot-starter-web 依赖项,启动应用程序也会在启动时不断崩溃 - Spring Boot app keeps crashing on startup even with spring-boot-starter-web dependency 未找到依赖项 'org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE' - Dependency 'org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE' not found 找不到 org.springframework.boot:spring-boot-starter-web:。 要求:项目: - Could not find org.springframework.boot:spring-boot-starter-web:. Required by: project : Mac上缺少spring-boot-starter-web hibernate-validator依赖项 - spring-boot-starter-web hibernate-validator dependency missing on Mac
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM