File tree Expand file tree Collapse file tree 6 files changed +130
-0
lines changed Expand file tree Collapse file tree 6 files changed +130
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
4
+ <modelVersion >4.0.0</modelVersion >
5
+ <parent >
6
+ <groupId >org.springframework.boot</groupId >
7
+ <artifactId >spring-boot-starter-parent</artifactId >
8
+ <version >1.5.20.RELEASE</version >
9
+ <relativePath /> <!-- lookup parent from repository -->
10
+ </parent >
11
+ <groupId >com</groupId >
12
+ <artifactId >caidapao</artifactId >
13
+ <version >0.0.1-SNAPSHOT</version >
14
+ <name >caidapao</name >
15
+ <description >Demo project for Spring Boot</description >
16
+
17
+ <properties >
18
+ <java .version>1.8</java .version>
19
+ </properties >
20
+
21
+ <dependencies >
22
+ <dependency >
23
+ <groupId >org.springframework.boot</groupId >
24
+ <artifactId >spring-boot-starter-web</artifactId >
25
+ </dependency >
26
+
27
+ <dependency >
28
+ <groupId >org.springframework.boot</groupId >
29
+ <artifactId >spring-boot-starter-test</artifactId >
30
+ <scope >test</scope >
31
+ </dependency >
32
+
33
+ <dependency >
34
+ <groupId >io.springfox</groupId >
35
+ <artifactId >springfox-swagger2</artifactId >
36
+ <version >2.2.2</version >
37
+ </dependency >
38
+
39
+ <dependency >
40
+ <groupId >io.springfox</groupId >
41
+ <artifactId >springfox-swagger-ui</artifactId >
42
+ <version >2.2.2</version >
43
+ </dependency >
44
+ </dependencies >
45
+
46
+ <build >
47
+ <plugins >
48
+ <plugin >
49
+ <groupId >org.springframework.boot</groupId >
50
+ <artifactId >spring-boot-maven-plugin</artifactId >
51
+ </plugin >
52
+ </plugins >
53
+ </build >
54
+
55
+ </project >
Original file line number Diff line number Diff line change
1
+ package com .caidapao ;
2
+
3
+ import org .springframework .boot .SpringApplication ;
4
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5
+
6
+ @ SpringBootApplication
7
+ public class CaidapaoApplication {
8
+
9
+ public static void main (String [] args ) {
10
+ SpringApplication .run (CaidapaoApplication .class , args );
11
+ }
12
+
13
+ }
Original file line number Diff line number Diff line change
1
+ package com .caidapao ;
2
+
3
+ import org .springframework .context .annotation .Bean ;
4
+ import org .springframework .context .annotation .Configuration ;
5
+ import springfox .documentation .builders .ApiInfoBuilder ;
6
+ import springfox .documentation .builders .PathSelectors ;
7
+ import springfox .documentation .builders .RequestHandlerSelectors ;
8
+ import springfox .documentation .service .ApiInfo ;
9
+ import springfox .documentation .spi .DocumentationType ;
10
+ import springfox .documentation .spring .web .plugins .Docket ;
11
+ import springfox .documentation .swagger2 .annotations .EnableSwagger2 ;
12
+
13
+ @ EnableSwagger2
14
+ @ Configuration
15
+ public class Swagger2 {
16
+
17
+ @ Bean
18
+ public Docket createRestApi (){
19
+ return new Docket (DocumentationType .SWAGGER_2 )
20
+ .apiInfo (apiInfo ())
21
+ .select ()
22
+ .apis (RequestHandlerSelectors .basePackage ("com.caidapao.web" ))
23
+ .paths (PathSelectors .any ())
24
+ .build ();
25
+ }
26
+
27
+ private ApiInfo apiInfo (){
28
+ return new ApiInfoBuilder ()
29
+ .title ("Spring Boot 中使用Swagger2构建RESTful APIs" )
30
+ .description ("更多Spring Boot相关文章请关注:http://www.caidapao.com/" )
31
+ .termsOfServiceUrl ("http://www.caidapao.com/" )
32
+ .contact ("蔡大炮" )
33
+ .version ("1.0" )
34
+ .build ();
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ package com .caidapao .web ;
2
+
3
+ import org .springframework .web .bind .annotation .RequestMapping ;
4
+ import org .springframework .web .bind .annotation .RestController ;
5
+
6
+ @ RestController
7
+ @ RequestMapping ("/user" )
8
+ public class UserController {
9
+ }
Original file line number Diff line number Diff line change
1
+ server.port =8080
Original file line number Diff line number Diff line change
1
+ package com .caidapao ;
2
+
3
+ import org .junit .Test ;
4
+ import org .junit .runner .RunWith ;
5
+ import org .springframework .boot .test .context .SpringBootTest ;
6
+ import org .springframework .test .context .junit4 .SpringRunner ;
7
+
8
+ @ RunWith (SpringRunner .class )
9
+ @ SpringBootTest
10
+ public class CaidapaoApplicationTests {
11
+
12
+ @ Test
13
+ public void contextLoads () {
14
+ }
15
+
16
+ }
You can’t perform that action at this time.
0 commit comments