搭建Swagger3.0

1.导入依赖

 <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

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

2.编写Swagger3的接口配置

@Configuration
@EnableOpenApi
public class SwaggerConfig{
	
	/**
     * 创建API
     */
    @Bean
    public Docket createRestApi()
    {
	    @Bean
	    public Docket createRestApi()
	    {
	        return new Docket(DocumentationType.OAS_30)
                // 是否启用Swagger
                .enable(true)
                // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
                .apiInfo(apiInfo())
                // 设置哪些接口暴露给Swagger展示
                .select()
                // 扫描指定包中的swagger注解 注意:不要扫描错误
                .apis(RequestHandlerSelectors.basePackage("com.gacrnd.web.controller"))
                .paths(PathSelectors.any())
                .build()
         }
    }
    
	/**
     * 添加摘要信息
     */
    private ApiInfo apiInfo()
    {
        // 用ApiInfoBuilder进行定制
        return new ApiInfoBuilder()
	         // 设置标题
	         .title("标题:_接口文档")
	         // 描述
	         .description("描述:")
	         // 作者信息
	         .contact(new Contact(aidexConfig.getName(), null, null))
	         // 版本
	         .version("版本号:" + aidexConfig.getVersion())
	         .build();
    }
}

3.注解

类注解:@API(tags = "说明")
方法注解:@ApiOperation(value = "Swagger3.0测试接口")

4.启动项目访问路径:http://项目地址:项目端口/swagger-ui/index.html
](https://img-blog.csdnimg.cn/direct/f97887d3326d44d4a78ee1f7c0c10d9a.png)

5.会遇到的问题
5.1: No operations defined in spec! 页面打开出现以下情况;
解决:检查扫描地址是否正确
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值