春季-避免混用版本

时间:2018-10-14 13:05:22

标签: spring maven spring-boot spring-data

在运行Spring Boot应用程序期间,出现以下错误:

试图调用方法org.springframework.web.reactive.function.client.WebClient.builder()Lorg/springframework/web/reactive/function/client/WebClient$Builder; but it does not exist. Its class, org.springframework.web.reactive.function.client.WebClient, is available from the following locations:

jar:file:/C:/Users/Wicia/.m2/repository/org/springframework/spring-web-reactive/5.0.0.M4/spring-web-reactive-5.0.0.M4.jar!/org/springframework/web/reactive/function/client/WebClient.class

它是从以下位置加载的:

file:/C:/Users/Wicia/.m2/repository/org/springframework/spring-web-reactive/5.0.0.M4/spring-web-reactive-5.0.0.M4.jar

操作:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.web.reactive.function.client.WebClient

我发现我应该为所有工件指定通用的弹簧版本(而不是混合使用),但是该怎么做呢?

这是我的pom.xml:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>5.0.0.M4</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web-reactive</artifactId>
    <version>5.0.0.M4</version>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-cassandra</artifactId>
    <version>2.1.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.0.5.RELEASE</version>
</dependency>

1 个答案:

答案 0 :(得分:0)

如果该依赖项由Spring管理,则不要在pom.xml中定义依赖项版本。而是使用spring-boot-starter-parent作为父母。

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web-reactive</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-cassandra</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
<dependencies>

Spring-boot-parent为几乎所有流行的依赖项定义了版本,因此默认情况下,您可以跳过定义版本。仅在遇到POM错误时定义它(这意味着您添加了不受Spring Boot管理的唯一依赖项)