gtxy0311

博客园 首页 新随笔 联系 订阅 管理
  1 随笔 :: 0 文章 :: 0 评论 :: 3 阅读

    第一步:引入swagger的依赖

  

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>


第二步:在config包下编写一个swaggerconfig配置类

@Configuration
@EnableSwagger2       // 开启swagger2
public class SwaggerConfig {

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("链接"))
.paths(PathSelectors.any())
.build();
}

private ApiInfo apiInfo() {
// 填写文档开发者信息
return new ApiInfoBuilder()
.title("主题")
.description("描述")
.version("1.0.0")
.build();
}
}

 

也可与在yml中控制swagger的开关

  1.  
    swagger: 
            enable:  true
第三步:启动访问项目
localhost:8080/swagger2-ui.html

 

 

 
posted on   没蜡笔的小新*  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示