spring - 如何在 IntelliJ 中使用 gradle 添加 spring-security-dependency ?

标签 spring spring-boot gradle spring-security build.gradle

我想使用依赖项: 实现“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')
}

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

Error-message when starting boot-run

这里是整个 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)
}

最佳答案

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

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

IntelliJ Offline Toggle

对于旧版本:

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

希望这会起作用。

关于spring - 如何在 IntelliJ 中使用 gradle 添加 spring-security-dependency ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62009906/

相关文章:

java - 扩展类中的 Spring Boot @Service 注解

java - 是否值得学习谷歌数据存储

java - 构造函数进行 Spring 依赖注入(inject) - 创建 bean 时出错,由 : java. lang.InknownClassChangeError 引起

spring boot 数据 cassandra 响应式(Reactive) JmxReporter 问题

gradle - 我如何知道gradle插件属性的评估何时会推迟?

java - MongoDB 与 Java 中的条件不同

java - 构建使用 JAVA 11 的 Docker 镜像

java - JpaRepository findAll 返回空列表

android - 将Android Studio更新到2.1.3版本后,Gradle构建卡住了

android - Android Studio无法同步Gradle项目