【问题标题】:Spring-Boot starter test import not resolvedSpring-Boot 启动器测试导入未解决
【发布时间】:2018-07-20 10:09:33
【问题描述】:
import org.springframework.test.context.junit4.SpringRunner;

无法解析测试包 Spring Boot 2.0.3 版 梯度版本 4.6 JDK 1.8

我正在使用 IntelliJ 社区版 IDE,我的操作系统是 ubuntu-16.04

还尝试过: 1-import springframework.boot.test 但这也不起作用 2-导航到项目目录并使用终端构建项目

我不想手动导入库。

Gradle 脚本:

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

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-spring-boot'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

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

【问题讨论】:

    标签: spring-boot gradle build.gradle ubuntu-16.04 spring-boot-test


    【解决方案1】:

    声明:testCompile("junit:junit"),不需要

    依赖:

    testCompile('org.springframework.boot:spring-boot-starter-test')
    

    解决以下类:

    import org.springframework.test.context.junit4.SpringRunner;
    

    【讨论】:

    • testCompile("junit:junit") 我需要,因为我导入了 org.junit.runner.RunWith;
    • 另外,我已经包含了这个依赖项,但它仍然无法正常工作
    • intelliJ 底部的构建窗口是否有错误?
    • 不,我尝试使用终端构建也都成功构建
    • 使用 Alt+Enter 并检查建议,然后单击在建议窗口中添加。相同的依赖项对我有用:依赖项 { compile('org.springframework.boot:spring-boot-starter-web') testCompile('org.springframework.boot:spring-boot-starter-test') }
    猜你喜欢
    • 1970-01-01
    • 2017-09-03
    • 2022-01-19
    • 1970-01-01
    • 2017-08-02
    • 2019-07-30
    • 2021-02-12
    • 2017-05-15
    • 1970-01-01
    相关资源
    最近更新 更多