Skip to content

Commit f8a3186

Browse files
committed
利用网关汇总API文档
1 parent 651953b commit f8a3186

File tree

10 files changed

+346
-0
lines changed

10 files changed

+346
-0
lines changed

2-Dalston版教程示例/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<module>eureka-feign-api</module>
3434
<module>eureka-feign-client</module>
3535
<module>eureka-feign-consumer</module>
36+
<module>eureka-feign-upload-client</module>
37+
<module>eureka-feign-upload-server</module>
3638

3739
<module>hystrix-collapser-provider</module>
3840
<module>hystrix-collapser-consumer</module>
@@ -42,6 +44,18 @@
4244

4345
<module>stream-hello</module>
4446

47+
<!--分布式跟踪-->
48+
<module>trace-1</module>
49+
<module>trace-2</module>
50+
51+
<module>zipkin-server</module>
52+
<module>zipkin-server-stream</module>
53+
54+
<!--swagger api 文档汇总-->
55+
<module>swagger-service-a</module>
56+
<module>swagger-service-b</module>
57+
<module>swagger-api-gateway</module>
58+
4559
</modules>
4660

4761
</project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>swagger-api-gateway</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>swagger-api-gateway</name>
12+
<description>Spring Cloud In Action</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.4.RELEASE</version>
18+
<relativePath/>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-zuul</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-eureka</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.spring4all</groupId>
37+
<artifactId>swagger-spring-boot-starter</artifactId>
38+
<version>1.7.0.RELEASE</version>
39+
</dependency>
40+
</dependencies>
41+
42+
<dependencyManagement>
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.springframework.cloud</groupId>
46+
<artifactId>spring-cloud-dependencies</artifactId>
47+
<version>Dalston.SR1</version>
48+
<type>pom</type>
49+
<scope>import</scope>
50+
</dependency>
51+
</dependencies>
52+
</dependencyManagement>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-maven-plugin</artifactId>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
63+
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.didispace;
2+
3+
import com.spring4all.swagger.EnableSwagger2Doc;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
import org.springframework.cloud.client.SpringCloudApplication;
6+
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
7+
import org.springframework.context.annotation.Primary;
8+
import org.springframework.stereotype.Component;
9+
import springfox.documentation.swagger.web.SwaggerResource;
10+
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
@EnableSwagger2Doc
16+
@EnableZuulProxy
17+
@SpringCloudApplication
18+
public class Application {
19+
20+
public static void main(String[] args) {
21+
new SpringApplicationBuilder(Application.class).web(true).run(args);
22+
}
23+
24+
@Component
25+
@Primary
26+
class DocumentationConfig implements SwaggerResourcesProvider {
27+
@Override
28+
public List<SwaggerResource> get() {
29+
List resources = new ArrayList<>();
30+
resources.add(swaggerResource("service-a", "/swagger-service-a/v2/api-docs", "2.0"));
31+
resources.add(swaggerResource("service-b", "/swagger-service-b/v2/api-docs", "2.0"));
32+
return resources;
33+
}
34+
35+
private SwaggerResource swaggerResource(String name, String location, String version) {
36+
SwaggerResource swaggerResource = new SwaggerResource();
37+
swaggerResource.setName(name);
38+
swaggerResource.setLocation(location);
39+
swaggerResource.setSwaggerVersion(version);
40+
return swaggerResource;
41+
}
42+
}
43+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
application:
3+
name: swagger-api-gateway
4+
5+
server:
6+
port: 11000
7+
8+
eureka:
9+
client:
10+
serviceUrl:
11+
defaultZone: http://eureka.didispace.com/eureka/
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>swagger-service-a</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>swagger-service-a</name>
12+
<description>Spring Cloud In Action</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.10.RELEASE</version>
18+
<relativePath/>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-eureka</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-web</artifactId>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>com.spring4all</groupId>
39+
<artifactId>swagger-spring-boot-starter</artifactId>
40+
<version>1.7.0.RELEASE</version>
41+
</dependency>
42+
</dependencies>
43+
44+
<dependencyManagement>
45+
<dependencies>
46+
<dependency>
47+
<groupId>org.springframework.cloud</groupId>
48+
<artifactId>spring-cloud-dependencies</artifactId>
49+
<version>Dalston.SR1</version>
50+
<type>pom</type>
51+
<scope>import</scope>
52+
</dependency>
53+
</dependencies>
54+
</dependencyManagement>
55+
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-maven-plugin</artifactId>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.didispace;
2+
3+
import com.spring4all.swagger.EnableSwagger2Doc;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.builder.SpringApplicationBuilder;
7+
import org.springframework.cloud.client.discovery.DiscoveryClient;
8+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@EnableSwagger2Doc
13+
@EnableDiscoveryClient
14+
@SpringBootApplication
15+
public class Application {
16+
17+
public static void main(String[] args) {
18+
new SpringApplicationBuilder(Application.class).web(true).run(args);
19+
}
20+
21+
@RestController
22+
class AaaController {
23+
24+
@Autowired
25+
DiscoveryClient discoveryClient;
26+
27+
@GetMapping("/service-a")
28+
public String dc() {
29+
String services = "Services: " + discoveryClient.getServices();
30+
System.out.println(services);
31+
return services;
32+
}
33+
34+
}
35+
36+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
spring.application.name=swagger-service-a
2+
server.port=10010
3+
4+
eureka.client.serviceUrl.defaultZone=http://eureka.didispace.com/eureka/
5+
6+
swagger.base-package=com.didispace
7+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>swagger-service-b</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>swagger-service-b</name>
12+
<description>Spring Cloud In Action</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.10.RELEASE</version>
18+
<relativePath/>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-eureka</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-web</artifactId>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>com.spring4all</groupId>
39+
<artifactId>swagger-spring-boot-starter</artifactId>
40+
<version>1.7.0.RELEASE</version>
41+
</dependency>
42+
</dependencies>
43+
44+
<dependencyManagement>
45+
<dependencies>
46+
<dependency>
47+
<groupId>org.springframework.cloud</groupId>
48+
<artifactId>spring-cloud-dependencies</artifactId>
49+
<version>Dalston.SR1</version>
50+
<type>pom</type>
51+
<scope>import</scope>
52+
</dependency>
53+
</dependencies>
54+
</dependencyManagement>
55+
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-maven-plugin</artifactId>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.didispace;
2+
3+
import com.spring4all.swagger.EnableSwagger2Doc;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.builder.SpringApplicationBuilder;
7+
import org.springframework.cloud.client.discovery.DiscoveryClient;
8+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@EnableSwagger2Doc
13+
@EnableDiscoveryClient
14+
@SpringBootApplication
15+
public class Application {
16+
17+
public static void main(String[] args) {
18+
new SpringApplicationBuilder(Application.class).web(true).run(args);
19+
}
20+
21+
@RestController
22+
class BbbController {
23+
24+
@Autowired
25+
DiscoveryClient discoveryClient;
26+
27+
@GetMapping("/service-b")
28+
public String dc() {
29+
String services = "Services: " + discoveryClient.getServices();
30+
System.out.println(services);
31+
return services;
32+
}
33+
34+
}
35+
36+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.application.name=swagger-service-b
2+
server.port=10020
3+
4+
eureka.client.serviceUrl.defaultZone=http://eureka.didispace.com/eureka/
5+
6+
swagger.base-package=com.didispace

0 commit comments

Comments
 (0)