简体   繁体   English

为什么我的项目找不到org.springframework.test或org.springframework.boot.test?

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

Problem: 问题:

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

Background 背景

I am trying to write a Unit test for a simple spring application. 我正在尝试为简单的Spring应用程序编写单元测试。 The application is built using Gradle. 该应用程序是使用Gradle构建的。 The following code is my build.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')
}

Attached is an image showing showing all the libraries associated with this project, which I believe includes the necessary test libraries. 随附的图片显示了与此项目相关的所有库,我相信其中包括必要的测试库。

在此处输入图片说明

Question

Why can't my project locate org.springframework.test or org.springframework.boot.test? 为什么我的项目找不到org.springframework.test或org.springframework.boot.test?

Attempts at solution 尝试解决

  • I have run gradle clean, followed by a build 我已经将gradle清理干净,然后进行构建

  • I have updated the maven central repository 我已经更新了Maven中央存储库

  • I tried to force the version of org.springframework:spring-* to a higher version (5.0.3.Release) 我试图将org.springframework:spring- *的版本强制为更高的版本(5.0.3.Release)

  • I tried using gradle-plugin:1.5.9.RELEASE 我尝试使用gradle-plugin:1.5.9.RELEASE

I figure I must be missing something in my build.gradle, but I am at my wits end as to what it is. 我认为我肯定在build.gradle中丢失了一些内容,但是我对它的内容一无所知。 Any help is appreciated. 任何帮助表示赞赏。 Thanks. 谢谢。

我已经复制了您的gradle配置,并且一切似乎都按预期进行,为避免有关启动新项目的任何问题,您可以从spring指南中下载此示例 ,然后根据需要自定义依赖项

暂无
暂无

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

相关问题 package org.springframework.boot.test 不存在 - package org.springframework.boot.test does not exist org.springframework.test也无法解决,同时存在maven依赖项 - org.springframework.test cannot be resolved also with maven dependency present 在NetBeans中将org.springframework.test包添加到spring-2.5.6-SEC01.jar - adding org.springframework.test package to spring-2.5.6-SEC01.jar in netbeans org.springframework.boot.test.mock.mockito.MockReset上的NoClassDefFoundError - NoClassDefFoundError on org.springframework.boot.test.mock.mockito.MockReset org.springframework.boot.SpringApplication无法解析 - org.springframework.boot.SpringApplication can not be resolved 找不到 org.springframework.boot:spring-boot-test-support:jar:2.2.6.RELEASE - Failure to find org.springframework.boot:spring-boot-test-support:jar:2.2.6.RELEASE 在哪里可以找到用于Spring Boot批注@SpringBootTest的Javadoc(即,用于org.springframework.boot.test.context包的Javadoc)? - Where can I find the Javadoc for Spring Boot Annotation @SpringBootTest (ie, for Package org.springframework.boot.test.context)? Spring Boot jUnit测试由于“ org.springframework.beans.factory.NoSuchBeanDefinitionException”而失败 - Spring boot jUnit test fails because of “org.springframework.beans.factory.NoSuchBeanDefinitionException” 使用org.springframework.test.util.ReflectionTestUtils测试方法 - Test a method using the org.springframework.test.util.ReflectionTestUtils 多模块项目的org.springframework.boot软件包不存在错误 - package org.springframework.boot does not exist error for multimodule project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM