高版本springboot整合swagger

第一次使用 高版本 springboot整合swagger存在一些问题,所以记录一下

这是我的springboot版本2.6: ![Alt](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdmF0YXIu

导入maven依赖(如果是高版本的别随便整合依赖会有问题):

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

然后是swagger配置类

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * swagger docket实例
     * @return
     */
    @Bean
    public Docket docket(){
        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true)              //是否激活swagger,如果是正式环境下,请把他设置为false
                .groupName("LittleFox")          //分组,可以设置多个docket
                .select()
                .paths(PathSelectors.any())
                .build();
    }


    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("LittleFox")
                .description("谷粒商城swagger")
                .version("1.0")
                .termsOfServiceUrl("termsOfServiceUrl")
                .contact(new Contact("name","url","email"))
                .build();
    }
//    下面的是默认配置 apiInfo.default
//    static {
//        DEFAULT = new ApiInfo("Api Documentation", "Api Documentation", "1.0", "urn:tos", DEFAULT_CONTACT, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList());
//    }
}

然后在应用swagger模块的配置类中加上,这个一定得加,不然启动不了

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

在你应用swagger的模块主启动一定要加上@ComponentScan(“com.atguigu”),不然打开swagger什么都没有

@SpringBootApplication
@MapperScan("com.atguigu.gulimall.product.dao")
@ComponentScan("com.atguigu")	//给swagger指定地点
@EnableDiscoveryClient

public class GulimallProductApplication {
    public static void main(String[] args) {
        SpringApplication.run(GulimallProductApplication.class,args);
    }
}

最后访问地址 http://localhost:10001/swagger-ui/ (端口号改成你自己的,其他不要变),就OK了
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值