IMPORTANT: This information is no longer actual. Apparently it was just a bug in Spring Initializr tool and Eureka is available with Spring Boot version 3.1.0 just fine.
If you’re using Spring Initializr tool for creating Spring Boot projects, you might have noticed a change. In Spring Boot version 3.1.0, the tool no longer allows you to select Eureka Discover Server. This came as a surprise to many developers, as Eureka Discovery server is a common component in Spring Boot microservices architecture. But don’t worry! You can still use Eureka Server with Spring Boot 3.1.0; it just requires a few manual adjustments.
How to Implement Eureka Discovery Server?
If the version of your Spring Boot project is 3.1.0 then you can still use Eureka Server but you will need to add its maven dependency manually. You will also need to make sure that you use a correct version of Spring Cloud. Otherwise, it will not work.
Eureka Discover Server Maven Dependency
Since Spring Initializr no longer offers the option to select Eureka Server as a Spring Cloud Discovery solution, you’ll need to make some manual changes to your project. Here’s how you can proceed:
- Create a Spring Boot project without selecting Eureka Server as a dependency. This project will serve as the base for our Eureka Server setup.
- Add Eureka Server dependency to your project’s pom.xml file manually. In your pom.xml file, add the following lines under the
<dependencies>
tag:
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
Also, ensure you include the Spring Cloud dependencies in the <dependencyManagement>
section:
<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>
- Ensure compatibility by using the correct version of Spring Cloud. For Spring Boot 3.1.0, the Spring Cloud version should be at least 2022.0.3. This can be defined in the
<properties>
section of your pom.xml:
<properties> <java.version>17</java.version> <spring-cloud.version>2022.0.3</spring-cloud.version> </properties>
An Example of a Complete pom.xml File
Here’s a complete example of a pom.xml file that uses Spring Boot 3.1.0, Eureka Discovery Server, and Spring Cloud version 2022.0.3. This should provide a template for setting up your own project.
<?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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.1.0</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.appsdeveloperblog.photoapp.discovery</groupId> <artifactId>PhotoAppDiscoveryService</artifactId> <version>0.0.1-SNAPSHOT</version> <name>PhotoAppDiscoveryService</name> <description>Photo App Eureka Discovery Server</description> <properties> <java.version>17</java.version> <spring-cloud.version>2022.0.3</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</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> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> </repositories> </project>
Conclusion
Implementing Eureka Discovery with Spring Boot 3.1.0 requires a few manual steps, but it’s still astraightforward process. By manually adding the Eureka Server dependency and using the correct Spring Cloud version, you can continue to use Eureka Discovery in your Spring Boot 3.1.0 projects.
If you’re new to this, the process might seem a bit daunting, but don’t worry! With practice, you’ll get the hang of it. The Spring ecosystem is vast and versatile, and getting comfortable with manipulating these elements manually will significantly boost your Spring Boot proficiency.
I hope you found this tutorial helpful. If you’re interested in learning more, check out my Spring Cloud and Spring Boot tutorials.
And remember, every great developer was once a beginner. Don’t hesitate to explore, make mistakes, and learn. Happy coding!