2

Im a beginner in Java so sorry in advance if I dont understand certain words.

I keep having the error: Cannot resolve symbol @EnableEurekaServer... When I manually type in the import line for eureka server, the word "cloud" is highlighted red in:

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

In my build.gradle file, I have

compile('org.springframework.cloud:spring-cloud-netflix-eureka-server')

Why does this happen... Everything looks like it's supposed to work. I can provide screenshots of things if asked!

My build.gradle file looks like this:

buildscript {
    ext {
        springBootVersion = '2.0.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.cloud:spring-cloud-netflix-eureka-server')
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

My EurekaApplicationServer.java looks like this:

package com.example.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
public class EurekaApplicationServer {

    public static void main(String[] args) {
        SpringApplication.run(EurekaApplicationServer.class, args);
    }

}

picture of err

Cœur
  • 37,241
  • 25
  • 195
  • 267
Syn
  • 938
  • 1
  • 10
  • 21
  • Please share the [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – CrazyCoder Mar 16 '18 at 19:58
  • I think I added enough information. Would love some help – Syn Mar 16 '18 at 20:09
  • Changing the dependency to `compile('org.springframework.cloud:spring-cloud-netflix-eureka-server:1.0.0.RELEASE')` fixes the problem for me. – CrazyCoder Mar 16 '18 at 20:16
  • Ok... It worked. Jesus christ. Thank you so much man. It was such a simple fix too. Is there a reason why it does this though? I like to understand why things went wrong. – Syn Mar 16 '18 at 20:18

3 Answers3

4

Use the dependency with the specific version, current version at the moment of this writing is:

compile('org.springframework.cloud:spring-cloud-netflix-eureka-server:1.4.3.RELEASE')

You can find the latest available version number here.

For Spring Boot projects when you don't specify the dependency version, the special dependency management plug-in is used. For some reason it fails to provide the version for this specific dependency. See the related question.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • Ahhh I see i see! thank you for explaining. Do you mind checking out this image and see if you can figure out why I am getting this error: https://imgur.com/a/5Dafv – Syn Mar 16 '18 at 21:20
  • work for after added last version in the dependency [https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server] ` org.springframework.cloud spring-cloud-starter-netflix-eureka-server 4.0.2 ` – Sangeeth Arulraj Jul 21 '23 at 06:26
0
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-eureka-server</artifactId>
    <version>1.1.6.RELEASE</version>
</dependency>

It worked for me.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
tarun kumar143
  • 391
  • 4
  • 7
-1

There is no need to lower down the version of eureka-server/client. The reason is that the maven repo cannot resolve the latest version of eureka server.To solve this, add repository to your pom/gradle file.

repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}

or

<repositories>
    <repository>
       <id>spring-milestones</id>
       <name>Spring Milestones</name>
       <url>https://repo.spring.io/libs-milestone</url>
       <snapshots>
           <enabled>false</enabled>
       </snapshots>
   </repository>

Hele
  • 24
  • 2