-
Notifications
You must be signed in to change notification settings - Fork 0
/
配置swagger2
64 lines (58 loc) · 2.15 KB
/
配置swagger2
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
52
53
54
55
56
57
58
59
60
61
62
63
64
配置swagger2
1、在pom.xml中配置信息
<!-- swagger start -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<!-- swagger end -->
2、在spring.xml配置文件中
<!-- swagger 配置 ,线上版本需要注释掉 -->
<bean class="com.inxedu.os.SwaggerConfiguration"/>
<!-- swagger ui resources-->
<mvc:default-servlet-handler />
3、配置Class
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @ClassName SwaggerConfiguration
* @Description: TODO
* @Author: lidong
* @CreateDate: 2018/5/30$ 2:37 PM$
* @UpdateUser: lidong
* @UpdateDate: 2018/5/30$ 2:37 PM$
* @UpdateRemark: TODO
* @Version: 1.0
**/
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket getApiInfo() {
ApiInfo apiInfo = new ApiInfoBuilder()
.title("使用Swagger2构建RESTful APIs")
.description("客户端与服务端接口文档")
.termsOfServiceUrl("http://localost:5000")
.contact("andy.li")
.version("1.0.0")
.build();
return new Docket(DocumentationType.SPRING_WEB)
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.basePackage("com.inxedu.os"))
.paths(PathSelectors.any())
.build();
}
}
4、在controller中添加自己配置的信息API等