• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

cokelike

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

swagger3 配置

在pom.xml添加swagger3.0的依赖:

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

创建SwaggerConfig 配置类

 

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@EnableOpenApi //使用Swagger3.0的Api文档
@Configuration
@EnableWebMvc //使能Swagger
public class SwaggerConfig{

    @Bean
    public Docket docketCategory() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                // 分组名称
                .groupName("default")
                //使能swagger
                .enable(true)
                .select()
                //设置接口包名
                .apis(RequestHandlerSelectors.basePackage("com.example.controler"))
                //设置请求路径开头的接口
                .paths(PathSelectors.ant("/**"))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口总览")
                .description("测试")
                .version("1.0")
                .build();
    }
}

  

 访问:http://localhost:8080/swagger-ui/index.html

posted on 2022-08-27 14:48  cokelike  阅读(56)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3