一. build.gradle引入包
https://mvnrepository.com/artifact/io.springfox/springfox-swagger2
https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui(该包里面本身含有显示页面)
或
https://mvnrepository.com/artifact/com.github.xiaoymin/swagger-bootstrap-ui
二. 创建SwaggerConfig配置类
@Configuration
@EnableSwagger2
//@EnableWebMvc
public class SwaggerConfig {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
. (\"swagger\")
.de ion(\"swagger API\")
.termsOfServiceUrl(\"http://blog.csdn.net/qq_27093465?viewmode=contents\")
.license(\"\")
.licenseUrl(\"\")
.version(\"1.0.0\")
.build();
}
}
三. WebConfig类添加静态资源访问路径
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
//swagger-ui页面显示
registry.addResourceHandler(\"/swagger-ui.html\")
.addResourceLocations(\"classpath:/ -INF/resources/swagger-ui.html\");
//doc.html页面显示
registry.addResourceHandler(\"/doc.html\")
.addResourceLocations(\"classpath:/ -INF/resources/doc.html\");
registry.addResourceHandler(\"/webjars/**\")
.addResourceLocations(\"classpath:/ -INF/resources/webjars/\");
}
目录
继续阅读与本文标签相同的文章
下一篇 :
云栖专辑| 阿里毕玄:程序员的成长路线
-
服务器远程的安全管理办法
2026-05-18栏目: 教程
-
语音顶会Interspeech 论文解读|Investigation of Transformer based Spelling Correction Model for CTC-based End-to-End Mandarin Speech Recognition
2026-05-18栏目: 教程
-
阿里云“网红"运维工程师白金:做一个平凡的圆梦人 | 9月11号栖夜读
2026-05-18栏目: 教程
-
十位大师零距离,云栖大会通票+限量周边,还不够诱人吗亲? | 开发者必读(062期)
2026-05-18栏目: 教程
-
相同类中方法间调用时日志Aop失效处理
2026-05-18栏目: 教程
