SpringBoot集成swagger2

SpringBoot集成swagger2

0x00 首先创建一个Springboot项目

0x01 pom.xml

可以去mvmrepository.com 搜索 springfox-swag
在这里插入图片描述
在pom.xml中添加这两个依赖,一个Swagger核心,一个是UI,选择最稳定版本 2.9.2,直接复制过来

		<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <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>

加载maven项目

0x02 配置Swagger2

创建配置
在这里插入图片描述

SwaggerConfig.java

package com.box.swagger.config;

import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2     //启动Swagger2
public class SwaggerConfig {
}

然后这个时候Swagger2就启动失败了
在这里插入图片描述
如果你的SpringBoot>= 2.6,就需要在 application.properties 添加
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
在这里插入图片描述
测试swagger2是否配置成功
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值