3. SpringBoot整合Swagger3.0
阿新 • • 發佈:2021-10-09
SpringBoot整合Swagger3.0
-
引入依賴
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
-
載入配置
@Configuration public class Swagger3Config { @Bean public Docket createRestApi() { return new Docket(DocumentationType.OAS_30) .apiInfo(apiInfo()) .select() // .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) //為當前包路徑 .apis(RequestHandlerSelectors.basePackage("控制層包")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Swagger3介面文件") .description("更多請諮詢服務開發者Ray。") .contact(new Contact("Ray。", "http://www.ruiyeclub.cn", "[email protected]")) .version("1.0") .build(); } }
-
Application類上加註解
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import springfox.documentation.oas.annotations.EnableOpenApi; @EnableOpenApi @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class,args); } }