一. 引入swagger相关依赖
<!--swagger-ui web界面-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--swagger相关注解依赖 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!--swagger-ui插件 可美化前端界面-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
二. 配置swagger
@Configuration
@EnableSwagger2 //开启swagger自动化配置
@EnableSwaggerBootstrapUI //启用SwaggerBootstrapUi提供的增强功能
public class SwaggerConfig {
@Bean
public Docket getDocket(){
ApiInfo apiInfo = new ApiInfoBuilder()
.title("xxx")
.description("xxx_1.0 操作文档")
//服务条款网址
.termsOfServiceUrl("https://blog.csdn.net/zxc_123_789")
.version("1.0")
.contact(new Contact("auther", "https://blog.csdn.net/zxc_123_789", "xxxx@qq.com"))
.build();
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo)
.select()
// 自行修改为自己的包路径
.apis(RequestHandlerSelectors.basePackage("org.ljh.web.controller"))
.paths(PathSelectors.any())
.build();
}
}
重启应用,浏览器访问http://localhost:8080/doc.html
或者http://localhost:8080/swagger-ui.html