【问题标题】:springframework.security package not found with starter-security dependency?springframework.security 包没有找到与 starter-security 依赖项?
【发布时间】:2016-01-29 17:43:30
【问题描述】:

我正在为我的项目使用 spring bootspring starter 依赖项。 我尝试在 Gradle 中使用 spring starter 安全依赖项,但在项目中找不到安全包。 IDE 是 IntelliJ IDEA‎。

我的 build.gradle 文件:

buildscript {
    ext {
        springBootVersion = '1.2.7.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
        classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
        classpath("org.springframework:springloaded:1.2.4.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot' 
apply plugin: 'io.spring.dependency-management' 

jar {
    baseName = 'hashfon-spring'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-hateoas')
    compile('org.springframework.boot:spring-boot-starter-jersey')
    compile('org.springframework.boot:spring-boot-starter-mustache')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-security')

    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
}

除了安全性之外的所有库都可以在外部库...

中找到

项目中类的一个例子:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.*;
import org.springframework.hateoas.*;
import org.springframework.mock.*;
import org.springframework.data.*;
import org.springframework.security.*;  //cannot resolve symbol!
/**
 * I can import all packages from external libraries except security
 */

附言。我尝试了很多不同版本的 spring-security-core,但没有任何反应。

【问题讨论】:

  • 这是您的实际导入语句吗?
  • @M.Deinum 是的,是的.. 找不到安全子文件夹:/
  • 这真的是您的导入声明吗?目前它是非法的,甚至无法编译,因为它缺少 .*;....
  • 你重新导入依赖了吗?
  • 转到查看->工具窗口->Gradle。单击最左侧的按钮(刷新)。这可能需要一段时间。

标签: java spring gradle spring-security dependency-management


【解决方案1】:

多次处理此问题后,我遇到了以下对我 100% 有效的解决方案:

  1. 转到文件|使缓存失效
  2. 删除存储所有依赖项的文件夹(~/.gradle/ 对于 UNIX 系统) - 如果在失效后存在
  3. 重启 Intellij IDEA
  4. 通过刷新 gradle 重新导入 gradle 依赖项:

【讨论】:

    猜你喜欢
    • 2020-08-15
    • 2020-11-08
    • 2017-07-24
    • 2018-01-10
    • 1970-01-01
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    相关资源
    最近更新 更多