Reputation:
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?
Upvotes: 22
Views: 89635
Reputation: 1
Give this code a try:
<?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>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gateway</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<spring-cloud.version>2023.0.1</spring-cloud.version>
</properties>
<dependencies>
<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>
</dependency>
</dependencies>
<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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Upvotes: 0
Reputation: 125
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>
Upvotes: 1
Reputation: 1
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>
Upvotes: 0
Reputation: 71
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
<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>
Upvotes: 0
Reputation: 1
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>
Upvotes: 0
Reputation: 2470
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.
Upvotes: 15
Reputation: 21
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>
Upvotes: 2
Reputation: 43
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.
Upvotes: 1
Reputation: 13
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>
Upvotes: -1
Reputation: 131
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>
Upvotes: 11
Reputation: 989
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>
Upvotes: 3
Reputation: 147
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.
Upvotes: 3