I am trying to setup a basic Eureka Service Discovery but, while implementing the same I am getting the following error:
org.springframework.context.ApplicationContextException: Unable to start web server
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:602) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.2.jar:3.1.2]
at com.project.discoveryserver.DiscoveryServerApplication.main(DiscoveryServerApplication.java:11) ~[classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat': org/springframework/web/client/RestClient$Builder
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:605) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:417) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1332) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1162) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:218) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-3.1.2.jar:3.1.2]
... 8 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/client/RestClient$Builder
at org.springframework.cloud.client.loadbalancer.LoadBalancerRestClientBuilderBeanPostProcessor.postProcessBeforeInitialization(LoadBalancerRestClientBuilderBeanPostProcessor.java:46) ~[spring-cloud-commons-4.1.0.jar:4.1.0]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:419) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) ~[spring-beans-6.0.11.jar:6.0.11]
... 25 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.web.client.RestClient$Builder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
... 29 common frames omitted
Moreover, while mentioning the port number and other config required for the eureka server in the application.properties file, it is showing the warning that the mentioned properties are not being used. Also attaching the pom.xml, application.properties and Main class for reference:
pom.xml:
<?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">
<parent>
<artifactId>microservices-project</artifactId>
<groupId>com.project</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>discovery-server</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-cloud.version>2023.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
</dependencies>
</project>
application.properties:
spring.application.name=discovery-server
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
server.port=8761
DiscoveryServerApplication class:
package com.project.discoveryserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class DiscoveryServerApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServerApplication.class, args);
}
}
to resolve the same I have tried to ensure the presence of the required JAR by:
- Checking iy my build configuration includes the spring-boot-starter-webflux dependency.
- Verified that the JARs for WebClient are properly downloaded and included in your project's classpath.
Attaching the dependency tree for spring-boot-starter-webflux for your reference:
\- org.springframework.boot:spring-boot-starter-webflux:jar:3.1.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter:jar:3.1.2:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:3.1.2:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:3.1.2:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:3.1.2:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.4.8:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.4.8:compile
[INFO] | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.20.0:compile
[INFO] | | | \- org.apache.logging.log4j:log4j-api:jar:2.20.0:compile
[INFO] | | \- org.slf4j:jul-to-slf4j:jar:2.0.7:compile
[INFO] | +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] | +- org.springframework:spring-core:jar:6.0.11:compile
[INFO] | | \- org.springframework:spring-jcl:jar:6.0.11:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.33:compile
[INFO] +- org.springframework.boot:spring-boot-starter-json:jar:3.1.2:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.15.2:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.15.2:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.15.2:compile
[INFO] | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.15.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:3.1.2:compile
[INFO] | \- io.projectreactor.netty:reactor-netty-http:jar:1.1.9:compile
[INFO] | +- io.netty:netty-codec-http:jar:4.1.94.Final:compile
[INFO] | | +- io.netty:netty-common:jar:4.1.94.Final:compile
[INFO] | | +- io.netty:netty-buffer:jar:4.1.94.Final:compile
[INFO] | | +- io.netty:netty-transport:jar:4.1.94.Final:compile
[INFO] | | +- io.netty:netty-codec:jar:4.1.94.Final:compile
[INFO] | | \- io.netty:netty-handler:jar:4.1.94.Final:compile
[INFO] | +- io.netty:netty-codec-http2:jar:4.1.94.Final:compile
[INFO] | +- io.netty:netty-resolver-dns:jar:4.1.94.Final:compile
[INFO] | | +- io.netty:netty-resolver:jar:4.1.94.Final:compile
[INFO] | | \- io.netty:netty-codec-dns:jar:4.1.94.Final:compile
[INFO] | +- io.netty:netty-resolver-dns-native-macos:jar:osx-x86_64:4.1.94.Final:compile
[INFO] | | \- io.netty:netty-resolver-dns-classes-macos:jar:4.1.94.Final:compile
[INFO] | +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.94.Final:compile
[INFO] | | +- io.netty:netty-transport-native-unix-common:jar:4.1.94.Final:compile
[INFO] | | \- io.netty:netty-transport-classes-epoll:jar:4.1.94.Final:compile
[INFO] | \- io.projectreactor.netty:reactor-netty-core:jar:1.1.9:compile
[INFO] | \- io.netty:netty-handler-proxy:jar:4.1.94.Final:compile
[INFO] | \- io.netty:netty-codec-socks:jar:4.1.94.Final:compile
[INFO] +- org.springframework:spring-web:jar:6.0.11:compile
[INFO] | +- org.springframework:spring-beans:jar:6.0.11:compile
[INFO] | \- io.micrometer:micrometer-observation:jar:1.11.2:compile
[INFO] | \- io.micrometer:micrometer-commons:jar:1.11.2:compile
[INFO] \- org.springframework:spring-webflux:jar:6.0.11:compile
The issue was resolved after changing the Spring Boot version in my parent microservice's
pom.xml
, attaching thepom.xml
for your reference: