Mama
Mama

Reputation: 635

EnableEurekaClient import doesn't exist

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

Upvotes: 16

Views: 26056

Answers (7)

Abhishek Ashware
Abhishek Ashware

Reputation: 47

For spring boot version 3.3.4 and above, use @EnableDiscoveryClient as @EnableEurekaClient is deprecated.

Upvotes: 0

Pratik Gaurav
Pratik Gaurav

Reputation: 907

Try using the new annotation provided by Eureka

@EnableDiscoveryClient

Upvotes: 1

Sagar Kapase
Sagar Kapase

Reputation: 51

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>

Upvotes: 5

Puneet Singh Parmar
Puneet Singh Parmar

Reputation: 41

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

Upvotes: 4

Saipriyadarshini Bandi
Saipriyadarshini Bandi

Reputation: 491

@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.

Upvotes: 43

PRao
PRao

Reputation: 1529

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

Upvotes: 15

Gregor Zurowski
Gregor Zurowski

Reputation: 2346

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

Upvotes: 0

Related Questions