1.引入依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<!--在引用时请在maven中央仓库搜索最新版本号-->
<version>2.0.2</version>
</dependency>
2. Swagger2Config 配置文件配置
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config implements WebMvcConfigurer {
@Profile({"dev", "sit"})
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build()
.ignoredParameterTypes(Timestamp.class);
}
@Profile({"dev", "sit"})
@Bean
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("标题")
.description("描述")
.termsOfServiceUrl("http://本机ip:端口/zlhj_telemarketing/doc.html")
.version("1.0")
.build();
}
}
项目启动,访问如下:
![访问启动示例](https://i-blog.csdnimg.cn/blog_migrate/a6f4a07da83f31767a3898d1043c80a6.png)