Skip to content

Commit 21e4268

Browse files
committed
服务网关Zuul的简单使用
1 parent f34fa91 commit 21e4268

File tree

11 files changed

+169
-124
lines changed

11 files changed

+169
-124
lines changed

api-gateway/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/

api-gateway/pom.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 https://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>2.0.2.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>cn.algerfan</groupId>
12+
<artifactId>api-gateway</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>api-gateway</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.cloud</groupId>
25+
<artifactId>spring-cloud-starter-config</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-test</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
43+
<dependencyManagement>
44+
<dependencies>
45+
<dependency>
46+
<groupId>org.springframework.cloud</groupId>
47+
<artifactId>spring-cloud-dependencies</artifactId>
48+
<version>${spring-cloud.version}</version>
49+
<type>pom</type>
50+
<scope>import</scope>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-maven-plugin</artifactId>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
64+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cn.algerfan.apigateway;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
6+
7+
/**
8+
* @author algerfan
9+
*/
10+
@SpringBootApplication
11+
@EnableZuulProxy
12+
public class ApiGatewayApplication {
13+
14+
public static void main(String[] args) {
15+
SpringApplication.run(ApiGatewayApplication.class, args);
16+
}
17+
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cn.algerfan.apigateway;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.cloud.context.config.annotation.RefreshScope;
5+
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
6+
import org.springframework.stereotype.Component;
7+
8+
/**
9+
* @author algerfan
10+
* @time 2019/8/27 20:46
11+
*/
12+
@Component
13+
public class ZuulConfig {
14+
15+
@ConfigurationProperties("zuul")
16+
@RefreshScope
17+
public ZuulProperties zuulProperties(){
18+
return new ZuulProperties();
19+
}
20+
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
eureka:
2+
client:
3+
service-url:
4+
defaultZone: http://127.0.0.1:8761/eureka/
5+
instance:
6+
prefer-ip-address: true
7+
spring:
8+
application:
9+
name: api-gateway
10+
cloud:
11+
config:
12+
discovery:
13+
enabled: true
14+
service-id: CONFIG
15+
profile: dev
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.algerfan.apigateway;
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 ApiGatewayApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

eureka/pom.xml

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<!-- TODO 2.0.0.M3 -->
98
<version>2.0.2.RELEASE</version>
109
<relativePath/> <!-- lookup parent from repository -->
1110
</parent>
@@ -17,7 +16,6 @@
1716

1817
<properties>
1918
<java.version>1.8</java.version>
20-
<!-- TODO Finchley.M2-->
2119
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
2220
</properties>
2321

@@ -54,43 +52,5 @@
5452
</plugin>
5553
</plugins>
5654
</build>
57-
58-
<!-- TODO repository-->
59-
<!--<repositories>
60-
<repository>
61-
<id>spring-snapshots</id>
62-
<name>Spring Snapshots</name>
63-
<url>https://repo.spring.io/snapshot</url>
64-
<snapshots>
65-
<enabled>true</enabled>
66-
</snapshots>
67-
</repository>
68-
<repository>
69-
<id>spring-milestones</id>
70-
<name>Spring Milestones</name>
71-
<url>https://repo.spring.io/milestone</url>
72-
<snapshots>
73-
<enabled>false</enabled>
74-
</snapshots>
75-
</repository>
76-
</repositories>
77-
<pluginRepositories>
78-
<pluginRepository>
79-
<id>spring-snapshots</id>
80-
<name>Spring Snapshots</name>
81-
<url>https://repo.spring.io/snapshot</url>
82-
<snapshots>
83-
<enabled>true</enabled>
84-
</snapshots>
85-
</pluginRepository>
86-
<pluginRepository>
87-
<id>spring-milestones</id>
88-
<name>Spring Milestones</name>
89-
<url>https://repo.spring.io/milestone</url>
90-
<snapshots>
91-
<enabled>false</enabled>
92-
</snapshots>
93-
</pluginRepository>
94-
</pluginRepositories>-->
95-
55+
9656
</project>

order/order-server/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<groupId>org.springframework.cloud</groupId>
1717
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
1818
</dependency>
19-
<!-- TODO spring-cloud-starter-feign ——> spring-cloud-starter-openfeign-->
2019
<dependency>
2120
<groupId>org.springframework.cloud</groupId>
2221
<artifactId>spring-cloud-starter-openfeign</artifactId>
@@ -37,8 +36,8 @@
3736
<groupId>org.springframework.boot</groupId>
3837
<artifactId>spring-boot-starter-data-redis</artifactId>
3938
</dependency>
40-
<!-- TODO spring-cloud-starter-hystrix ——> spring-cloud-starter-netflix-hystrix-->
41-
<!-- TODO 2.0.2.RELEASE需要引入-->
39+
<!-- spring-cloud-starter-hystrix ——> spring-cloud-starter-netflix-hystrix-->
40+
<!-- 2.0.2.RELEASE没有web依赖-->
4241
<dependency>
4342
<groupId>org.springframework.boot</groupId>
4443
<artifactId>spring-boot-starter-web</artifactId>

order/pom.xml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<parent>
1111
<groupId>org.springframework.boot</groupId>
1212
<artifactId>spring-boot-starter-parent</artifactId>
13-
<!-- TODO 2.0.0.M3 -->
1413
<version>2.0.2.RELEASE</version>
1514
<relativePath/>
1615
</parent>
@@ -23,7 +22,6 @@
2322

2423
<properties>
2524
<java.version>1.8</java.version>
26-
<!-- TODO Finchley.M2-->
2725
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
2826
<product-client.version>0.0.1-SNAPSHOT</product-client.version>
2927
<product-common.version>0.0.1-SNAPSHOT</product-common.version>
@@ -41,41 +39,4 @@
4139
</dependencies>
4240
</dependencyManagement>
4341

44-
<!-- <repositories>
45-
<repository>
46-
<id>spring-snapshots</id>
47-
<name>Spring Snapshots</name>
48-
<url>https://repo.spring.io/snapshot</url>
49-
<snapshots>
50-
<enabled>true</enabled>
51-
</snapshots>
52-
</repository>
53-
<repository>
54-
<id>spring-milestones</id>
55-
<name>Spring Milestones</name>
56-
<url>https://repo.spring.io/milestone</url>
57-
<snapshots>
58-
<enabled>false</enabled>
59-
</snapshots>
60-
</repository>
61-
</repositories>
62-
<pluginRepositories>
63-
<pluginRepository>
64-
<id>spring-snapshots</id>
65-
<name>Spring Snapshots</name>
66-
<url>https://repo.spring.io/snapshot</url>
67-
<snapshots>
68-
<enabled>true</enabled>
69-
</snapshots>
70-
</pluginRepository>
71-
<pluginRepository>
72-
<id>spring-milestones</id>
73-
<name>Spring Milestones</name>
74-
<url>https://repo.spring.io/milestone</url>
75-
<snapshots>
76-
<enabled>false</enabled>
77-
</snapshots>
78-
</pluginRepository>
79-
</pluginRepositories>-->
80-
8142
</project>

product/pom.xml

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<parent>
1111
<groupId>org.springframework.boot</groupId>
1212
<artifactId>spring-boot-starter-parent</artifactId>
13-
<!-- TODO 2.0.0.M3 -->
1413
<version>2.0.2.RELEASE</version>
1514
<relativePath/>
1615
</parent>
@@ -23,7 +22,6 @@
2322

2423
<properties>
2524
<java.version>1.8</java.version>
26-
<!-- TODO Finchley.M2-->
2725
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
2826
</properties>
2927

@@ -39,42 +37,4 @@
3937
</dependencies>
4038
</dependencyManagement>
4139

42-
<!-- TODO repository-->
43-
<!--<repositories>
44-
<repository>
45-
<id>spring-snapshots</id>
46-
<name>Spring Snapshots</name>
47-
<url>https://repo.spring.io/snapshot</url>
48-
<snapshots>
49-
<enabled>true</enabled>
50-
</snapshots>
51-
</repository>
52-
<repository>
53-
<id>spring-milestones</id>
54-
<name>Spring Milestones</name>
55-
<url>https://repo.spring.io/milestone</url>
56-
<snapshots>
57-
<enabled>false</enabled>
58-
</snapshots>
59-
</repository>
60-
</repositories>
61-
<pluginRepositories>
62-
<pluginRepository>
63-
<id>spring-snapshots</id>
64-
<name>Spring Snapshots</name>
65-
<url>https://repo.spring.io/snapshot</url>
66-
<snapshots>
67-
<enabled>true</enabled>
68-
</snapshots>
69-
</pluginRepository>
70-
<pluginRepository>
71-
<id>spring-milestones</id>
72-
<name>Spring Milestones</name>
73-
<url>https://repo.spring.io/milestone</url>
74-
<snapshots>
75-
<enabled>false</enabled>
76-
</snapshots>
77-
</pluginRepository>
78-
</pluginRepositories>-->
79-
8040
</project>

product/product-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<groupId>org.springframework.cloud</groupId>
2929
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
3030
</dependency>
31-
<!-- TODO 2.0.2.RELEASE需要引入-->
31+
<!-- 2.0.2.RELEASE没有web依赖-->
3232
<dependency>
3333
<groupId>org.springframework.boot</groupId>
3434
<artifactId>spring-boot-starter-web</artifactId>

0 commit comments

Comments
 (0)