简体   繁体   中英

Adding Spring Cloud Config to boot app causes java.lang.NoSuchMethodError by adding unwanted jar to class path

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM