swagger3出来后一直没有用今天搞了demo搞了一波
线路
pom引入->application配置-->java代码拦截配置--->启动参数
MAVEN配置引入jar包
<!-- Swagger API文档 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
application 配置文件
spring.mvc.pathmatch.matching-strategy=ant_path_matcher //springboot 低版本要加
springfox.documentation.swagger-ui.base-url= /documentation
springfox.documentation.swagger-ui.enabled=true
java代码配置
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
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;
import java.time.LocalDate;
@Configuration
public class Swagger3Config {
@Bean
public Docket petApi() {
ApiInfo apiInfo = new ApiInfoBuilder().title("Spring Boot swagger3 整合")
.contact(new Contact("IT实验室", "https://tanli.com", "tanli_0908@163.com"))
.description("Spring Boot 版本2.7、Swagger3 整合")
.license("Apache 2.0")
.licenseUrl("https:///spring-boot-swagger3-tutorial/main/LICENSE")
.version("1.0")
.termsOfServiceUrl("服务条款URL")
.build();
return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.directModelSubstitute(LocalDate.class, String.class)
.genericModelSubstitutes(ResponseEntity.class)
.useDefaultResponseMessages(false)
.enableUrlTemplating(true);
}
}
启动配置(相比Swagger2特殊点)
启动类中加入注解: @EnableOpenApi
SpringBoot整合Swagger3教程
本文介绍了如何在SpringBoot项目中集成Swagger3,从添加Maven依赖到配置application文件,再到Java代码设置Docket,最后启用OpenAPI。示例详细展示了配置过程,包括ApiInfo的构建和启动参数。
1618

被折叠的 条评论
为什么被折叠?



