【问题标题】:gradle package org.springframework.test.context does not existgradle 包 org.springframework.test.context 不存在
【发布时间】:2019-10-12 11:45:36
【问题描述】:

我正在尝试使用依赖项“testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.18.RELEASE'” 当我运行 gradle clean build 时购买它显示

错误:包 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'


}

这是错误:

任务:编译Java失败 D:\projects\personal\wiring-beans\src\main\java\soundsystem\CDPlayerTest.java:8: 错误:包 org.springframework.test.context 不存在导入 org.springframework.test.context.ContextConfiguration; ^ D:\projects\personal\wiring-beans\src\main\java\soundsystem\CDPlayerTest.java:9: 错误:包 org.springframework.test.context.junit4 不存在 进口 org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ^ D:\projects\personal\wiring-beans\src\main\java\soundsystem\CDPlayerTest.java:12: 错误:找不到符号 @ContextConfiguration(classes = CDPlayerConfig.class) ^ 符号:类 ContextConfiguration D:\projects\personal\wiring-beans\src\main\java\soundsystem\CDPlayerTest.java:11: 错误:找不到符号@RunWith(SpringJUnit4ClassRunner.class) ^ 符号:类 SpringJUnit4ClassRunner 4 错误

【问题讨论】:

  • 停止混合来自不同 spring 版本的 jars/modules。永远不要混合来自等待发生的麻烦的框架的不同版本的 jar。您正在混合 4.1.6、4.3.18 和 5.1.2 并发现它不起作用很奇怪。将不同模块的版本对齐到一个版本。

标签: spring gradle


【解决方案1】:

我发现创建 Spring 项目最简单、最安全的方法是使用 Spring 的handy-dandy project intializer

只需选择“Gradle Project”、“Java”、“2.25”(Spring Boot 的稳定版本 em>),填写项目的“Group”和“Artifact”的值。

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

下载生成的启动项目后,构建它。几乎可以保证一开始就成功构建。因为 Spring 已经为你处理好了所有必需的依赖和传递依赖。

即使您决定不将自己的项目基于该启动项目(我建议不要这样做),您至少可以看到正确配置的 Spring 项目应该是什么样子.

【讨论】:

  • 嗨,对不起,这是一个春季项目,不是弹簧靴
猜你喜欢
  • 2013-08-21
  • 1970-01-01
  • 2022-06-16
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-08
  • 2013-07-31
相关资源
最近更新 更多