20

I am following a tutorial to learn eureka server/client with spring boot when I try to install maven dependencies in the pom.xml I get the error in the title

this is my pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.nlimits</groupId>
    <artifactId>movie_info_service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>movie_info_service</name>
    <description>Movie Info Service</description>

    <properties>
        <java.version>11</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

How can I solve this problem and why is it happening?

11 Answers11

13

I too am following a tutorial as well.

I created a basic microservice using Spring Boot in IntelliJ 2020.1

I added the spring-cloud-starter-netflix-eureka-client starter to my project.

Here is what was added to the pom.xml:

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

 <dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-dependencies</artifactId>
  <version>Hoxton.SR8</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>

After reloading the maven pom.xml file, I get the error that dependency is not found.

Here is the error:

Cannot resolve org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:unknown

I am using Spring Boot 2.3.5.

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>

SOLUTION :

For some reason, the version of the eureka discovery client is not added automatically to the pom when using the spring initializr to add the spring-boot-starter. So I added the version manually:

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

Then after refreshing the maven pom.xml the dependency was recognized.

ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
Amir
  • 1,422
  • 1
  • 15
  • 28
  • Adding the version allowed compilation but generated errors during start up. Instead,I added the 2020.0.3 under the java version; then, a dependencyManagement section below as shown by @nidhal louremi – chelista Jun 08 '21 at 02:51
  • you can find the different version in site https://mvnrepository.com/ this site is for dependencies, just search and use the different version. – norullah karimi Sep 02 '23 at 16:03
10

just add this code after <dependencies/> section and before <build/> section:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-parent</artifactId>
            <version>Greenwich.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
Co ti
  • 124
  • 2
  • 13
nidhal louremi
  • 111
  • 1
  • 5
3

Check the Spring boot Starter version (2.3.3) and Spring Cloud version (2.2.5), it fails your build, I recommend to use Spring Initializer to create your pom/build file for your project.

Abrar Ansari
  • 127
  • 8
  • How does this answer my question:How can I solve this problem and why is it happening? –  Sep 01 '20 at 18:48
  • 1
    your spring-boot-starter-parent version is 2.3.3 and your spring-cloud-starter-netflix-eureka-client version is 2.3.3 if you read the spring doc you will see that the current version for spring-cloud-* is 2.2.5. – Abrar Ansari Sep 01 '20 at 18:51
  • I used spring.initilizer to build my project but still can't find the dependency – Amir Nov 05 '20 at 14:37
3

I managed to solve this problem by adding spring cloud version in properties.

<properties>
    <java.version>11</java.version>
    <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
</properties>
Jakov
  • 879
  • 2
  • 17
  • 36
  • I added this property as well to my project, but still unable to load eureka-discovery-client – Amir Nov 05 '20 at 14:36
2

Change the spring boot version (and the spring cloud version) in the pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.5.RELEASE</version>
    <relativePath/> 
</parent>

<properties>
    <java.version>11</java.version>
    <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
nakiDevI
  • 21
  • 1
1

I realized the jar files are downloaded into "Maven Dependencies" in the project folder but the POM error still exist.

Solution:- Delete the C:\Users<user>.m2 folder and then reload maven from POM.

Mathan
  • 43
  • 1
  • 9
1

Step 1: Add spring-cloud.version tag in pom.xml as show below. Ofcourse you can change the version or use below mention version.

<properties>
    ...
    <spring-cloud.version>2021.0.8</spring-cloud.version>
    ...
</properties>

Step 2: Add dependency as show below

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

Step 3: Add dependency management tag just below 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>
0

Adding the version of eureka discovery client manually can help to resolve the problem. I added the version and it worked.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>2.2.10.RELEASE</version>
</dependency>
nakhodkin
  • 1,327
  • 1
  • 17
  • 27
0

Follow below example. Added something you not have on your pom.xml please ignore the comment; when you are done, please check your type, this is case sensitive. My example using server. Hope work on related issue

    <properties>
<!-- using java 17 -->
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
<!--optional(?)-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
<!-- the main problem here(?)-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

info:

file|Project Structure -> project -> SDK: SDK corretto-17


during process check the color of your code example:

//todo: it goes red.. must have different color 
@EnableEurekaServer

It supposed to be red. If red is fine.. don't added this line

//todo: added by importing
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

you must reload the maven (it take times.. for me take 2 minutes) in order to download what you needed. Then put your cursor on the red code until pop-up

cannot resolve symbol Bla bla

then click import the class. Result you should have

package com.***.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//todo: added by importing 
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
//todo added application and server
@SpringBootApplication
@EnableEurekaServer
//just example name
public class EurekaServerApplication {
//todo: make main
}

If nothing happen, then you should follow some suggestion

  1. downgrade your script. Were Bad idea
  2. downgrade your java. Still bad idea, I'm using 17, while new java version on this moment are 19.
  3. check the version on your code. When I make this, there is version below the on the example and my working code, the line not used it. the version said on the pom.xml (parent) were

<spring.cloud-version>2020.0.3</spring.cloud-version>

If you find the current version not worked. Please added comment for it.

disclamer: using Intellij Idea.

source: youtube

with keyword #servicediscovery #microservices #amigoscode

For compare purpose I'm posting root pom.xml for refences only

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.***code</groupId>
  <artifactId>***services</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>***services</name>
  <url>http://www.***services.com</url>

  <modules>
<!--something here not wanted to share-->
    <module>eureka-server</module>
  </modules>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <spring.boot.maven.plugin.version>2.5.7</spring.boot.maven.plugin.version>
    <spring.boot.dependency.version  >2.5.7</spring.boot.dependency.version>
    <spring.cloud-version>2020.0.3</spring.cloud-version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring.boot.dependency.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <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>

  <dependencies>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <version>${spring.boot.maven.plugin.version}</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
0

I tried adding dependencyManagement under dependencies it worked

<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>
-1

At Spring Start, when creating the project, also take the repositories, these guys are fundamental.

<repositories>
      // DATA
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      // DATA
    </pluginRepository>
    <pluginRepository>
      // DATA
    </pluginRepository>
  </pluginRepositories>