目录
Swagger简介
1.导入坐标
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j</artifactId>
<version>3.0.3</version>
</dependency>
2.Bean相关配置
在SpringMvc提供的组件配置器中书写
@Bean
public Docket docket1() {
log.info("准备生成接口文档");
ApiInfo apiInfo = new ApiInfoBuilder()
.title("项目接口文档")
.version("2.0")
.description("项目接口文档")
.build();
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.groupName("管理端接口")
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
.paths(PathSelectors.any())
.build();
return docket;
}
3.配置静态资源映射
/**
* 设置静态资源映射
* @param registry
*/
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
log.info("开始设置静态资源映射... ");
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}