From ef6467882d50ad29852b6a0c4eed232c4ca26708 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?=
<2291200076@qq.com>
Date: Sat, 5 Nov 2022 20:25:37 +0800
Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AEGateway=EF=BC=88Gateway?=
=?UTF-8?q?=E4=B8=8D=E6=8A=A5=E9=94=99=EF=BC=8C=E4=BD=86=E6=89=BE=E4=B8=8D?=
=?UTF-8?q?=E5=88=B0=E6=9C=8D=E5=8A=A1=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/microservice-gateway/pom.xml | 21 +++++++++++++++++++
.../src/main/java/com/cxyxiaomo/App.java | 13 ------------
.../main/java/com/cxyxiaomo/epp/Gateway.java | 12 +++++++++++
.../src/main/resources/application.yml | 18 ++++++++++++++++
.../src/test/java/com/cxyxiaomo/AppTest.java | 20 ------------------
.../java/com/cxyxiaomo/epp/GatewayTest.java} | 2 +-
.../microservice-provider-test-8011/pom.xml | 13 ++++++++++++
backend/pom.xml | 12 +++++++++++
8 files changed, 77 insertions(+), 34 deletions(-)
delete mode 100644 backend/microservice-gateway/src/main/java/com/cxyxiaomo/App.java
create mode 100644 backend/microservice-gateway/src/main/java/com/cxyxiaomo/epp/Gateway.java
create mode 100644 backend/microservice-gateway/src/main/resources/application.yml
delete mode 100644 backend/microservice-gateway/src/test/java/com/cxyxiaomo/AppTest.java
rename backend/{microservice-provider-test-8011/src/test/java/com/cxyxiaomo/epp/AppTest.java => microservice-gateway/src/test/java/com/cxyxiaomo/epp/GatewayTest.java} (91%)
diff --git a/backend/microservice-gateway/pom.xml b/backend/microservice-gateway/pom.xml
index 75c2848..296aaa7 100644
--- a/backend/microservice-gateway/pom.xml
+++ b/backend/microservice-gateway/pom.xml
@@ -23,6 +23,27 @@
junit
test
+
+ org.springframework.cloud
+ spring-cloud-starter-gateway
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+
+ ch.qos.logback
+ logback-core
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ slf4j-simple
+
diff --git a/backend/microservice-gateway/src/main/java/com/cxyxiaomo/App.java b/backend/microservice-gateway/src/main/java/com/cxyxiaomo/App.java
deleted file mode 100644
index 796b015..0000000
--- a/backend/microservice-gateway/src/main/java/com/cxyxiaomo/App.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.cxyxiaomo;
-
-/**
- * Hello world!
- *
- */
-public class App
-{
- public static void main( String[] args )
- {
- System.out.println( "Hello World!" );
- }
-}
diff --git a/backend/microservice-gateway/src/main/java/com/cxyxiaomo/epp/Gateway.java b/backend/microservice-gateway/src/main/java/com/cxyxiaomo/epp/Gateway.java
new file mode 100644
index 0000000..6157933
--- /dev/null
+++ b/backend/microservice-gateway/src/main/java/com/cxyxiaomo/epp/Gateway.java
@@ -0,0 +1,12 @@
+package com.cxyxiaomo.epp;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Gateway {
+ public static void main(String[] args) {
+ SpringApplication.run(Gateway.class, args);
+ }
+}
+
diff --git a/backend/microservice-gateway/src/main/resources/application.yml b/backend/microservice-gateway/src/main/resources/application.yml
new file mode 100644
index 0000000..dc1d61d
--- /dev/null
+++ b/backend/microservice-gateway/src/main/resources/application.yml
@@ -0,0 +1,18 @@
+server:
+ port: 80
+
+# Spring 配置
+spring:
+ application:
+ name: microservice-gateway
+ cloud:
+ gateway:
+ discovery:
+ locator:
+ enabled: true
+ lower-case-service-id: true
+ routes:
+ - id: test
+ uri: lb://microservice-provider-test-8011
+ predicates:
+ - Path=/test/**
diff --git a/backend/microservice-gateway/src/test/java/com/cxyxiaomo/AppTest.java b/backend/microservice-gateway/src/test/java/com/cxyxiaomo/AppTest.java
deleted file mode 100644
index ef44881..0000000
--- a/backend/microservice-gateway/src/test/java/com/cxyxiaomo/AppTest.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.cxyxiaomo;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
-{
- /**
- * Rigorous Test :-)
- */
- @Test
- public void shouldAnswerWithTrue()
- {
- assertTrue( true );
- }
-}
diff --git a/backend/microservice-provider-test-8011/src/test/java/com/cxyxiaomo/epp/AppTest.java b/backend/microservice-gateway/src/test/java/com/cxyxiaomo/epp/GatewayTest.java
similarity index 91%
rename from backend/microservice-provider-test-8011/src/test/java/com/cxyxiaomo/epp/AppTest.java
rename to backend/microservice-gateway/src/test/java/com/cxyxiaomo/epp/GatewayTest.java
index b3dda20..61aea9e 100644
--- a/backend/microservice-provider-test-8011/src/test/java/com/cxyxiaomo/epp/AppTest.java
+++ b/backend/microservice-gateway/src/test/java/com/cxyxiaomo/epp/GatewayTest.java
@@ -7,7 +7,7 @@ import org.junit.Test;
/**
* Unit test for simple App.
*/
-public class AppTest
+public class GatewayTest
{
/**
* Rigorous Test :-)
diff --git a/backend/microservice-provider-test-8011/pom.xml b/backend/microservice-provider-test-8011/pom.xml
index cf03d61..065b99f 100644
--- a/backend/microservice-provider-test-8011/pom.xml
+++ b/backend/microservice-provider-test-8011/pom.xml
@@ -27,5 +27,18 @@
org.springframework.boot
spring-boot-starter-web
+
+
+ ch.qos.logback
+ logback-core
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ slf4j-simple
+
diff --git a/backend/pom.xml b/backend/pom.xml
index 97ce6ca..2cfc762 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -46,6 +46,18 @@
pom
import
+
+
+ org.springframework.cloud
+ spring-cloud-starter-gateway
+ 3.1.4
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+ 3.1.4
+
org.springframework.boot