簡體   English   中英

為什么我的項目找不到org.springframework.test或org.springframework.boot.test?

[英]Why can't my project locate org.springframework.test or org.springframework.boot.test?

問題:

Error:(15, 10) java: cannot find symbol
  symbol: class SpringRunner
Error:(16, 2) java: cannot find symbol
  symbol: class SpringBootTest
Error:(12, 47) java: package org.springframework.test.context.junit4 does not exist
Error:(10, 47) java: package org.springframework.test.context.junit4 does not exist
/home/ian/Development/JavaEE/RestCalculator/src/main/java/com/testApp/calculator/ApplicationTest.java
Error:(11, 45) java: package org.springframework.boot.test.context does not exist

背景

我正在嘗試為簡單的Spring應用程序編寫單元測試。 該應用程序是使用Gradle構建的。 以下代碼是我的build.gradle。

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'calculator'
    version =  '0.1.0'
}

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

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    compile("org.springframework.kafka:spring-kafka:1.3.2.RELEASE")
    testCompile('junit:junit:4.12')
    compile('junit:junit:4.12')
}

隨附的圖片顯示了與此項目相關的所有庫,我相信其中包括必要的測試庫。

在此處輸入圖片說明

為什么我的項目找不到org.springframework.test或org.springframework.boot.test?

嘗試解決

  • 我已經將gradle清理干凈,然后進行構建

  • 我已經更新了Maven中央存儲庫

  • 我試圖將org.springframework:spring- *的版本強制為更高的版本(5.0.3.Release)

  • 我嘗試使用gradle-plugin:1.5.9.RELEASE

我認為我肯定在build.gradle中丟失了一些內容,但是我對它的內容一無所知。 任何幫助表示贊賞。 謝謝。

我已經復制了您的gradle配置,並且一切似乎都按預期進行,為避免有關啟動新項目的任何問題,您可以從spring指南中下載此示例 ,然后根據需要自定義依賴項

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM