EnableEurekaClient import doesn’t exist

Issue

I added spring-cloud-starter-netflix-eureka-client gradle depedency in my project and shrik the depedency. But when go use @EnableEurekaClient in my Main class it show me suggestion create @EnableEurekaClient annotation. Don’t show any import file of eureka client.

Unresolved reference: EnableEurekaClient

productserviceApplication.kt

  package com.main.productservice

    import org.springframework.boot.autoconfigure.SpringBootApplication
    import org.springframework.boot.runApplication

    @SpringBootApplication
    @EnableEurekaClient
    class ProductServiceApplication

    fun main(args: Array<String>) {
        runApplication<ProductServiceApplication>(*args)
    }

gradle.kt

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.5.2"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.5.20"
    kotlin("plugin.spring") version "1.5.20"
}

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

repositories {
    mavenCentral()
}

dependencies {
    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.jetbrains.kotlin:kotlin-stdlib-jdk8")
        implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client")
        testImplementation("org.springframework.boot:spring-boot-starter-test")
    }

    tasks.withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs  listOf("-Xjsr305strict")
            jvmTarget  "11"
        }
    }

    tasks.withType<Test> {
        useJUnitPlatform()
    }

I am getting error at @EnableEurekaClient

Solution

Make sure to import the Spring Cloud BOM in your Gradle build definition:

extra["springCloudVersion"]  "2020.0.3"

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

The EnableEurekaClient annotation is in package org.springframework.cloud.netflix.eureka. You should add the following import to your main application file:

import org.springframework.cloud.netflix.eureka.EnableEurekaClient

Answered By – Gregor Zurowski

Leave a Comment