gpt4 book ai didi

spring-boot - Kotlin Spring Boot 注解处理 "Cannot Resolve Configuration Processing"

转载 作者:行者123 更新时间:2023-12-02 13:40:32 25 4
gpt4 key购买 nike

我无法正确注入(inject) @Value我的 Kotlin Spring Boot 应用程序中的应用程序属性。我的 application.yml 中定义的属性文件,随后在 additional-spring-configuration-metadata.json 中引用文件(在资源 -> META-INF 下),未正确添加到 bean 表达式上下文中。使用 IntelliJ version 2020.2.1 ,当我将鼠标悬停在该属性上时,我看到了 Cannot resolve configuration property错误。尝试运行应用程序(将配置属性值构造注入(inject)到类中)会导致 Unsatisfied dependency expressed through constructor parameter错误。
build.gradle.kts


plugins {
id("org.springframework.boot") version "2.3.3.RELEASE"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
kotlin("jvm") version "1.3.72"
kotlin("plugin.spring") version "1.3.72"
}

group = "com.myProject"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

extra["springCloudVersion"] = "Hoxton.SR8"

dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("org.springframework.boot:spring-boot-configuration-processor:2.3.3.RELEASE")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
testImplementation("io.projectreactor:reactor-test")
}

buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("com.google.cloud.tools:appengine-gradle-plugin:2.2.0")
}
}

apply(plugin = "com.google.cloud.tools.appengine")

configure<com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlExtension> {
deploy {
projectId = "my-cloud-project"
version = "GCLOUD_CONFIG"
}
}

dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
错误信息
Spring error modal
附加 Spring 配置元数据.json
{
"properties": [
{
"name": "otherApi.baseUrl",
"type": "java.lang.String",
"description": "Description for otherApi.baseUrl."
}
]
}
我添加了注释处理依赖项,使缓存无效并重新启动,并使用了 Kotlin 特定的注释处理器 (kapt)。我也按照这里的说明进行操作: https://www.jetbrains.com/help/idea/annotation-processors-support.html
我错过了什么?任何和所有的帮助将不胜感激。谢谢!

最佳答案

您需要将以下内容声明为 annoatationProcessor

implementation("org.springframework.boot:spring-boot-configuration-processor:2.3.3.RELEASE")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:2.3.3.RELEASE")

关于spring-boot - Kotlin Spring Boot 注解处理 "Cannot Resolve Configuration Processing",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63840637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com