Myles W
Myles W

Reputation: 63

Kotlin Spring Boot Annotation Processing "Cannot Resolve Configuration Processing"

I am unable to properly inject an @Value application property in my Kotlin Spring Boot application. The property as defined in my application.yml file, and subsequently referenced in an additional-spring-configuration-metadata.json file (under resources -> META-INF), is not properly being added to the bean expression context. Using IntelliJ version 2020.2.1, when I hover over the property, I see a Cannot resolve configuration property error. Attempting to run the application (with the configuration property value construction-injected into a class) leads to a Unsatisfied dependency expressed through constructor parameter error.

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"
    }
}

Error Message Spring error modal

additional-spring-configuration-metadata.json

{
  "properties": [
    {
      "name": "otherApi.baseUrl",
      "type": "java.lang.String",
      "description": "Description for otherApi.baseUrl."
    }
  ]
}

I've added annotation processing dependencies, invalidated caches and restarted, and played around with Kotlin specific annotation processors (kapt). I've also followed the instructions here: https://www.jetbrains.com/help/idea/annotation-processors-support.html

What am I missing? Any and all help would be appreciated. Thanks!

Upvotes: 3

Views: 1253

Answers (2)

PrasadU
PrasadU

Reputation: 2438

You need to declare the below as an annotationProcessor

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

to

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

Upvotes: 0

Dmitriy Fialkovskiy
Dmitriy Fialkovskiy

Reputation: 3225

If your application.yml (or application.properties) looks like this:

spring:
    datasource:
        username: postgres
        password: postgres
        url: jdbc:postgresql://localhost:5433/company
        driver-class-name: org.postgresql.Driver

then try to rewrite each property to full-name format for every property:

spring.datasource.username: postgres
spring.datasource.password: postgres
spring.datasource.url: jdbc:postgresql://localhost:5433/company
spring.datasource.driver-class-name: org.postgresql.Driver

Upvotes: 0

Related Questions