0

I have a working Spring boot app. I changed the application to read its configuration from Spring Cloud Config server. I added bootstrap.properties and the following dependencies to the pom:

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

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

The version of spring cloud is 2020.0.4. The app successfully retrieves its configuration from the config server. However, the endpoints fail with the following error:

in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'void javax.ws.rs.core.MultivaluedMap.addAll(java.lang.Object, java.lang.Object[])'] with root cause
java.lang.NoSuchMethodError: 'void javax.ws.rs.core.MultivaluedMap.addAll(java.lang.Object, java.lang.Object[])'

I have run the boot application in debug mode to see what the Tomcat classpath is. Prior to adding Spring Cloud Config , there was only

jakarta.ws.rs-api-2.1.6.jar

on the classpath. However after adding the config server dependencies

jsr311-api-1.1.1.jar is showing up on the Tomcat classpath before the Jakarta library and hence why this is happening.

I am not sure why the addition of Spring Cloud Config dependencies to my pom and adding a property file would cause this addition to the classpath.

I am running/building the app using mvn spring-boot:run.

How do I fix this issue?

Update: it seems that the jsr311-api-1.1.1.jar gets pulled in by spring-cloud-starter-netflix-eureka-client

Thank you.

João Dias
  • 16,277
  • 6
  • 33
  • 45
Sufie
  • 1
  • 1
  • My guess is the added dependency changed the class path order. You need to exclude the offending dependency – spencergibb Nov 02 '21 at 02:34
  • Further investigation: jsr311-api-1.1.1.jar gets pulled in by spring-cloud-starter-netflix-eureka-client. But I need this dependency. Otherwise I can't discover the config server. – Sufie Nov 02 '21 at 05:23

1 Answers1

0

I have added the following to my pom.xml and I can reach my application endpoints successfully.

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        <exclusions>
              <exclusion>
                    <groupId>javax.ws.rs</groupId>
                    <artifactId>jsr311-api</artifactId>
              </exclusion>
        </exclusions>
</dependency>
Sufie
  • 1
  • 1