首页 > 解决方案 > 如何在 IntelliJ 中使用 gradle 添加 spring-security-dependency?

问题描述

我想使用依赖项: implementation 'org.springframework.boot:spring-boot-starter-security' 在我的 IntelliJ 项目中,但出于任何原因,它无法解决此依赖项。

这些是我的依赖项。相关的是spring-boot-starter-security.

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
runtime('org.springframework.boot:spring-boot-devtools')
}

出于任何原因,我在启动引导运行时收到此错误消息:

启动启动运行时的错误消息

这里是整个 build.gradle 文件:

    plugins {
    id 'org.springframework.boot' version '2.2.7.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'de.hohenheim'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.h2database:h2'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    runtime('org.springframework.boot:spring-boot-devtools')
}

test {
    useJUnitPlatform()
}

bootRun {
    sourceResources(sourceSets.main)
}

标签: springspring-bootgradlespring-securitybuild.gradle

解决方案


您需要重新启用 Gradle 在线模式

对于最新版本的 IntelliJ IDE,请在此处找到一个选项:

IntelliJ 离线切换

对于旧版本:

  1. 喜好
  2. 进入构建、执行、部署。
  3. 最后选择 Gradle。
  4. 取消选中离线工作。单击应用然后确定。

希望这会奏效。


推荐阅读