Gradle软件包org.springframework.test.context不存在



我正在尝试使用"依赖项" testCompile组:'org.springframework',name:'spring-test',版本:'4.3.18.Release'运行Gradle Clean Build It显示

错误:软件包org.springframework.test.context不存在导入org.springframework.test.context.contextconfiguration;

这是我的build.gradle

/*
 * This build file was auto generated by running the Gradle 'init' task
 * by 'diego.virguez' at '5/22/19 10:16 AM' with Gradle 2.14.1-rc-1
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.14.1-rc-1/userguide/tutorial_java_projects.html
 */
// Apply the java plugin to add support for Java
apply plugin: 'java'
// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenLocal()
    mavenCentral()
}
// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.21'
    compile 'org.springframework:spring-webmvc:4.1.6.RELEASE'
    compile 'junit:junit:4.12'
    compile 'javax.servlet:jstl:1.2'


    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'
    testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.18.RELEASE'
    //testCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1-b09'
    compile group: 'org.springframework', name: 'spring-tx', version: '5.1.2.RELEASE'

}

这是错误:

任务:compilejava失败 D: Projects Projects persony 接线 Src Main Java Soundsystem CDPLAYERTEST.JAVA:8: 错误:软件包org.springframework.test.context不存在导入 org.springframework.test.context.contextconfiguration; ^ d: projects projects persony bieting-beans src main java soundsystem cdplayertest.java:9: 错误:不存在 进口 org.springframework.test.context.junit4.springjunit4classrunner; ^ d: projects projects persony 接线 src src main java soundsystem cdplayertest.java:12: 错误:找不到符号@ContextConfiguration(class = cdplayerconfig.class( ^符号:类contextConfiguration D: Projects Projects persony 接线 Src Main Java Soundsystem CDPLAYERTEST.JAVA:11:11: 错误:找不到符号@runwith(springjunit4classrunner.class( ^符号:类SpringJunit4Classrunner 4错误

我发现,创建一个春季项目的最简单,大多数失败的方法是使用spring的 handy dandy project intializer 。。

只需选择" gradle project ",„ java ",„ 2.25 "(稳定版本的Spring Boot (,填写项目的" group "和„ artifact "。"。

在" 搜索依赖项中,要添加"字段,您将输入„ web ",然后选择提出的内容。然后只需单击绿色" 生成项目"按钮。

下载生成的入门项目后,构建它。几乎可以保证,可以成功地建造大门。因为所有所需的依赖关系和及时依赖性都已在春季为您提供了照顾。

即使您决定不将自己的项目基于该开始项目(我建议反对(,您至少将能够看到正确配置的春季项目的样子。