Spring boot 集成 knife
程序员文章站
2022-06-28 16:36:03
Spring boot 集成 knife添加依赖开启配置添加依赖com.github.xiaoymin knife4j-spring-boot-starter 2.0.4 <...
添加依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<!--在引用时请在maven*仓库搜索最新版本号-->
<version>2.0.4</version>
</dependency>
开启配置
package com.commons.config;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @author jiezhigang
* @title:
* @projectName assets
* @description:
* @date 2020/11/2
*/
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfiguration {
@Bean(value = "defaultApi2")
public Docket defaultApi2() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
//分组名称
.groupName("2.X版本")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.assets.mvc.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("swagger-bootstrap-ui RESTful APIs")
.description("swagger-bootstrap-ui")
.termsOfServiceUrl("http://localhost:8999/")
.contact("developer@mail.com")
.version("1.0")
.build();
}
}
本文地址:https://blog.csdn.net/jzg5845201314/article/details/109628855
推荐阅读
-
Spring boot外部配置(配置中心化)详解
-
IntelliJ IDEA 创建spring boot 的Hello World 项目(图解)
-
利用Spring Boot如何开发REST服务详解
-
Spring Boot与Kotlin处理Web表单提交的方法
-
Spring Boot 中application.yml与bootstrap.yml的区别
-
Intellij IDEA创建spring-boot项目的图文教程
-
ThinkPad T43 集成网卡的 Boot Agent 设置
-
Spring Boot整合WebSocket
-
Spring Boot 日志配置方法(超详细)
-
Spring Boot修改启动端口的方法