代码之家  ›  专栏  ›  技术社区  ›  Jesse

未解析的引用:WebSecurityConfigurerAdapter,带有弹簧启动启动器安全性Gradle/Kotlin

  •  0
  • Jesse  · 技术社区  · 3 年前

    我刚开始使用Gradle和Kotlin,我正在尝试为我的SpringBoot应用程序设置一个简单的API密钥身份验证。我在build.gradle.kts文件中添加了spring-boot-starter安全性,但在SecurityConfig文件中

    org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter 未解决。其他安全进口产品也不错。例如

    org.springframework.security.config.annotation.web.builders.HttpSecurity 工作得很好。我正在使用Intellij,我认为这可能是缓存问题,但在使缓存无效后,它仍然存在。

    这是我的build.gradle.kts文件。

    plugins {
        id("org.springframework.boot") version "3.0.6"
        id("io.spring.dependency-management") version "1.1.0"
        id("io.freefair.lombok") version "8.0.1"
        kotlin("jvm") version "1.7.22"
        kotlin("plugin.spring") version "1.7.22"
    }
    
    group = "com.demo"
    version = "0.0.1-SNAPSHOT"
    java.sourceCompatibility = JavaVersion.VERSION_17
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
        implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
        implementation("org.springframework.boot:spring-boot-starter-web")
        implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
        implementation("org.jetbrains.kotlin:kotlin-reflect")
        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")
        testImplementation("org.springframework.security:spring-security-test")
    }
    
    tasks.withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs = listOf("-Xjsr305=strict")
            jvmTarget = "17"
        }
    }
    
    tasks.withType<Test> {
        useJUnitPlatform()
    }
    

    我指的是这篇媒体文章: https://medium.com/techwasti/enable-spring-security-using-kotlin-6b9abb36d218

    我的SecurityConfig文件位于src/main/kotlin/com.demo.dashboard/config下。

    我试着重新启动IDE,在build.gradle.kts文件中以不同的方式引用spring安全依赖项,并用从一开始就选择的依赖项重新初始化项目,但我运气不佳。

    1 回复  |  直到 3 年前
        1
  •  0
  •   impune    3 年前

    看起来像 WebSecurityConfigurerAdapter has been deprecated last year ,在Spring Security 5.7中。

    通过在java文档中的快速搜索, the class no longer exists in 6.0.3 (latest version) 。从您发布的build.gradle文件来看,您使用的是最新版本。

    第一个链接下的文章描述了配置弹簧安全性的替代方法。 This article 也可能有帮助。

    推荐文章