SpringCloud整合Swagger2报错compatible version of org.springframework.plugin.core.PluginRegistry

前言

这是SpringCloud整合Swagger2的第一个坑。对于Swagger2这种技术其实没太多必要深入学习,知道怎么整合,集成微服务,一些注解的使用即可,不用像其他的一些框架一样,如Spring、SpringBoot这种就需要深入源码搞懂底层逻辑!

报错

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method org.springframework.plugin.core.PluginRegistry.getPluginFor(Ljava/lang/Object;)Ljava/util/Optional; but it does not exist. Its class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:

    jar:file:/C:/Users/TAO/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

It was loaded from the following location:

    file:/C:/Users/TAO/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry

首先这个问题产生的原因我说一下:由于Spring启动需要PluginRegistry类,但是在spring-plugin-core-1.2.0.RELEASE.jar 中找不到PluginRegistry,意思也就是说我们的spring-plugin-core这个依赖的版本高了,或者是低了,但是一般都是版本过低导致的!

微服务整合Swagger2

项目结构
在这里插入图片描述

pom依赖
我这里只演示Swagger2整合相关的核心依赖

	<parent>
        <artifactId>yy-common</artifactId>
        <groupId>com.tao</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <description>yy swagger</description>
    <artifactId>yy-swagger</artifactId>

     <dependencies>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.fox.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.fox.version}</version>
        </dependency>
    </dependencies>

User项目导入Swagger2依赖
在这里插入图片描述

编写相应的SwaggerAutoConfig配置类
这个我就不提供代码了,网上多的是,按照通用的代码copy一下即可

启动
启动后那么你就会看到上面的报错

问题分析

思路
首先报错中有这么一段信息Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry,这个报错信息已经可以注意告诉我们这里的导包有问题,然后上面有个提示有问题的包org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar,对就是这个jar包!我们右键User项目的pom文件查看依赖关系!
在这里插入图片描述
Ctrl+F查找一下这个版本有问题的依赖spring-plugin-core-1.2.0.RELEASE.jar
在这里插入图片描述
找到这个spring-plugin-core-1.2.0.RELEASE.jar版本有问题的依赖了,然后我们顺瓜摸藤,到他的引用处
在这里插入图片描述
问题就在这个springfox-swagger2的依赖中!那么我们就有解决方案了,而且有多种

  1. 在swagger2项目中将springfox-swagger2依赖中的这个依赖spring-plugin-core手动排除
  2. 在父pom中指定依赖spring-plugin-core的版本推荐使用,因为便于后期统一维护

解决问题
在这里插入图片描述

			<dependency>
                <groupId>org.springframework.plugin</groupId>
                <artifactId>spring-plugin-core</artifactId>
                <version>2.0.0.RELEASE</version>
            </dependency>

补充
如果项目中像我这里一样还整合了SpringSecurity的话,建议使用第二种方式处理,因为在SpringSecurity中也存在一个spring-plugin-core

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员劝退师-TAO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值