英文:
Unresolved reference: WebSecurityConfigurerAdapter with spring-boot-starter-security Gradle/Kotlin
问题
I am new to using Gradle and Kotlin, and I am trying to set up a simple API key authentication for my Spring Boot application. I added spring-boot-starter-security to my build.gradle.kts file, but in my SecurityConfig file, the import for org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
is unresolved. The other security imports are fine. For example, org.springframework.security.config.annotation.web.builders.HttpSecurity
works just fine. I am using Intellij, and I thought maybe it was a caching issue, but it has persisted after invalidating cache, as well.
Here is my build.gradle.kts file.
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()
}
I am referencing this medium article: https://medium.com/techwasti/enable-spring-security-using-kotlin-6b9abb36d218
My SecurityConfig file is under src/main/kotlin/com.demo.dashboard/config.
I tried restarting the IDE, referencing the spring security dependency in different ways in the build.gradle.kts file, and re-initializing the project with the dependency selected from the start, but I have had no luck.
英文:
I am new to using Gradle and Kotlin, and I am trying to set up a simple API key authentication for my Spring Boot application. I added spring-boot-starter-security to my build.gradle.kts file, but in my SecurityConfig file, the import for
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
is unresolved. The other security imports are fine. For example,
org.springframework.security.config.annotation.web.builders.HttpSecurity
works just fine. I am using Intellij, and I thought maybe it was a caching issue, but it has persisted after invalidating cache, as well.
Here is my build.gradle.kts file.
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()
}
I am referencing this medium article: https://medium.com/techwasti/enable-spring-security-using-kotlin-6b9abb36d218
My SecurityConfig file is under src/main/kotlin/com.demo.dashboard/config.
I tried restarting the IDE, referencing the spring security dependency in different ways in the build.gradle.kts file, and re-initializing the project with the dependency selected from the start, but I have had no luck.
答案1
得分: 0
WebSecurityConfigurerAdapter
看起来在 Spring Security 5.7 中已被弃用,详见此链接。
从您提供的 build.gradle 文件来看,您正在使用最新版本,但是从 java doc 中的查询来看,该类在 6.0.3(最新版本)中已不再存在,详见此链接。
第一个链接下的文章描述了配置 Spring Security 的替代方法,这篇文章 也可能会有所帮助。
英文:
Looks like WebSecurityConfigurerAdapter
has been deprecated last year, in Spring Security 5.7.
From quick search in the java doc, the class no longer exists in 6.0.3 (latest version). From the build.gradle file you posted, you are using the latest version.
The article under first link describes alternative approaches to configuring spring security.
This article may also be helpful.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论