lidongdong
2022-12-06 229223286a57c66beac1fa411c8494f64495abfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.dg.core.task;
 
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
import java.util.ArrayList;
 
@Configuration
@EnableSwagger2
public class SwaggerConfig {
 
    //配置了Swagger的Docket的bean实例
    @Bean
    public Docket docket(Environment environment){
 
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true) //配置是否启用Swagger,如果是false,在浏览器将无法访问
                .select()// 通过.select()方法,去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .apis(RequestHandlerSelectors.basePackage("com.dg.core"))
                // 配置如何通过path过滤,即这里只扫描请求以/longdi开头的接口
//                .paths(PathSelectors.ant("/longdi/**"))
                .build();
 
    }
 
 
    //配置文档信息
    private ApiInfo apiInfo() {
        Contact contact = new Contact("花城e+", "http://localhost:8181/swagger-ui/index.html", "项目");
        return new ApiInfo(
                "花城e+接口文档", // 标题
                "花城e+接口文档", // 描述
                "v1.0", // 版本
                "http://localhost:8181/swagger-ui/index.html", // 组织链接
                contact, // 联系人信息
                "Apach 2.0 许可", // 许可
                "许可链接", // 许可连接
                new ArrayList<>()// 扩展
        );
    }
 
}