我刚开始使用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安全依赖项,并用从一开始就选择的依赖项重新初始化项目,但我运气不佳。