gradle пакет org.springframework.test.context не существует - PullRequest
0 голосов

Я пытаюсь использовать зависимость "testCompile group: 'org.springframework', имя: 'spring-test', версия: '4.3.18.RELEASE'" покупка, когда я запускаю gradle clean build, она показывает

ошибка: пакет org.springframework.test.context не существует import 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 FAILED D: \ projects \ personal \ wiring-beans \ src \ main \ java \ soundsystem \ CDPlayerTest.java: 8: ошибка: пакет org.springframework.test.context не существует import 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 ошибки

1 Ответ

0 голосов
/ 27 мая 2019

Я обнаружил, что самый простой и надежный способ создания проекта Spring - использовать удобный инициализатор проекта Spring .

Просто выберите « Gradle Project «,« Java »,« 2.25 »( стабильная версия Spring Boot ), заполните значения для вашего проекта« Группа » и « Артефакт ».

В поле « Поиск зависимостей для добавления » введите « web «и выберите то, что представлено.Затем просто нажмите зеленую кнопку « Generate Project ».

После загрузки созданного начального проекта создайте его.Это в значительной степени гарантировано, чтобы построить успешно прямо у ворот.Потому что все необходимые и транзитивные зависимости позаботились о вас в Spring.

Даже если вы решите не основывать свой собственный проект на этом начальном проекте (, который я бы посоветовал против ) вы хотя бы сможете увидеть, как должен выглядеть правильно настроенный проект Spring.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...