spring boot 2.6.2 集成 springfox3.0

springfox3.0与spring boot 2.6.2集成之后,发现swagger3.0的简直粗暴 无需任何配置,项目就能直接在spring boot 中启动成功。主要得益于spring boot 的自动配置。在配置文件中提供了自动开启和相应的项目。其配置项是

spring.mvc.pathmatch.matching-strategy=ant_path_matcher // 此配置项是因为spring boot 2.6.2 不兼容部分问题导致的
springfox.documentation.swagger-ui.enabled=false //spring boot提供的自动开启或者关闭。 线上关闭 线下开启

1. 添加项目依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>

2. 不需要在其controller main添加注解,启动之后就可以看到默认的运行

 

 访问地址是: UI : http://localhost:8080/swagger-ui/index.html#/

doc :http://localhost:8080/v3/api-docs

3. 如果调整配置

package com.example.springfox.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
* @author: hett
* @date: 2022/1/17 10:13
*/
@Configuration
public class SwaggerConfig {

@Bean
Docket docket(){
//选择版本3
return new Docket(DocumentationType.OAS_30)
//选择生成的接口文档
.select()
// //包所在的路径
.apis(RequestHandlerSelectors.basePackage("com.example.springfox.controller"))
//默认报下所有的接口都生成
.paths(PathSelectors.any())
.build()
//接口文档初始化
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.description("hett")
.contact(new Contact("hett",null,"1771084007@qq.com"))
.version("1.0")
.title("fox test")
.build();
}
}
//可以把配置文件写在一个属性中
调整之后的结果

 

posted @ 2022-01-17 10:39  李悠然  阅读(1803)  评论(0编辑  收藏  举报