使用swagger3是项目无法启动 或 无法获取api信息解决方法

报错

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

 解决办法:将依赖中的spring-plugin-core去除,并添加高版本。解决之后依赖如下:

 <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>3.0.2</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.plugin</groupId>
                    <artifactId>spring-plugin-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
  
         <dependency>
            <groupId>org.springframework.plugin</groupId>
            <artifactId>spring-plugin-core</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Java中使用Swagger可以通过以下步骤来实现: 1. 在你的Maven或Gradle项目中添加Swagger的依赖项。例如,对于Maven项目,可以在`pom.xml`文件中添加以下内容: ```xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> ``` 2. 创建一个配置类来启用Swagger。在该类上使用`@EnableSwagger2`注解,如下所示: ```java import org.springframework.context.annotation.Configuration; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class SwaggerConfig { } ``` 3. 创建一个API控制器类,并使用Swagger的注解来描述API接口。例如: ```java import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; @RestController @RequestMapping("/api") @Api(tags = "示例API") public class SampleController { @GetMapping("/hello") @ApiOperation("获取欢迎信息") public String hello() { return "Hello, Swagger!"; } @PostMapping("/user") @ApiOperation("创建用户") public User createUser(@RequestBody User user) { // 处理创建用户的逻辑 return user; } // 其他API接口... } ``` 4. 启动你的应用程序,并访问Swagger UI界面。Swagger UI界面默认可以通过`http://localhost:8080/swagger-ui.html`进行访问。你将能够看到由Swagger自动生成的API文档,并可以在界面上进行交互测试和调试。 请注意,上述示例中使用了Spring Boot和Springfox Swagger来演示使用Swagger的过程。你可以根据你的项目框架和需要进行相应的调整。另外,还可以通过注解来进一步定制API文档的展示效果和描述信息。 希望这些步骤能够帮助你在Java项目中成功使用Swagger

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值