EnableEurekaClient import doesn't exist
Asked Answered
C

6

15

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("-Xjsr305=strict")
            jvmTarget = "11"
        }
    }
    
    tasks.withType<Test> {
        useJUnitPlatform()
    }

I am getting error at @EnableEurekaClient

Corwun answered 7/7, 2021 at 11:38 Comment(0)
I
0

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
Infusive answered 7/7, 2021 at 12:17 Comment(0)
D
41

@EnableEurekaClient is deprecated, no need to annotate the main class. It is enough to add the spring-cloud-starter-netflix-eureka-client dependency to pom.xml and if we have the application name in yml or properties file it will be registered to Eureka Server.

Darden answered 20/9, 2021 at 6:29 Comment(0)
S
15

This is an error with version 2022.0.1, with this version you need to use @EnableDiscoveryClient or use the version 2020.0.3 for @EnableEurekaClient

Sternwheeler answered 27/2, 2023 at 8:36 Comment(1)
or 2021.0.3 :))Leg
Q
5

If you are using latest version of Spring boot then use @EnableDiscoveryClient annotation on Spring boot application.

  1. Dependency :

    <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka- client</artifactId> </dependency>

  2. Outside the dependencies tag :

    <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

3.In Properties tag :

<spring-cloud.version>2022.0.4</spring-cloud.version>
Quintero answered 14/9, 2023 at 7:4 Comment(0)
T
4

If you are latest version then use @EnableDiscoveryClient in Place of @EnableEurekaClient in main file

Thankless answered 28/8, 2023 at 6:39 Comment(0)
K
1

Try using the new annotation provided by Eureka

@EnableDiscoveryClient
Katlin answered 8/5, 2024 at 22:50 Comment(0)
I
0

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
Infusive answered 7/7, 2021 at 12:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.