1.引入依赖
<!--SwaggerUI-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--Swagger2-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
2.配置swagger以及信息
@Configuration
@EnableSwagger2 //开启Swagger
public class SwaggerConfig {
// 配置首页信息
@Bean
public Docket docket(){
//RequestHandlerSelectors.basePackage("com.wl.controller") 扫描指定的包
// paths() 需要过滤的路径
// enable配置是否启动 默认为true
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
.enable(true)
.select()
.apis(RequestHandlerSelectors.basePackage("com.wl.controller"))
// .paths(PathSelectors.ant(""))
.build();
}
private ApiInfo apiInfo(){
// 作者姓名 项目路径
Contact DEFAULT_CONTACT = new Contact("wl", "", "2315290571@qq.com");
return new ApiInfo("wl测试的api文档",
"即使再小的帆也能远航",
"1.0",
"http://localhost:8080/hello",
DEFAULT_CONTACT,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList()
);
}
}