Gateway配置文件
This commit is contained in:
		@@ -283,6 +283,10 @@ Spring initializr:https://start.spring.io/
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.5&packaging=jar&jvmVersion=11&groupId=com.cxyxiaomo&artifactId=entrance&name=Epidemic%20prevention%20platform&description=&packageName=com.cxyxiaomo.entrance&dependencies=lombok,mysql,mybatis
 | 
					https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.5&packaging=jar&jvmVersion=11&groupId=com.cxyxiaomo&artifactId=entrance&name=Epidemic%20prevention%20platform&description=&packageName=com.cxyxiaomo.entrance&dependencies=lombok,mysql,mybatis
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##### Gateway
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					B站教程:https://www.bilibili.com/video/BV1JB4y1F7aL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Maven
 | 
					#### Maven
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MVN REPOSITORY:https://mvnrepository.com/
 | 
					MVN REPOSITORY:https://mvnrepository.com/
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								backend/.idea/runConfigurations/Gateway.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								backend/.idea/runConfigurations/Gateway.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					<component name="ProjectRunConfigurationManager">
 | 
				
			||||||
 | 
					  <configuration default="false" name="Gateway" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
 | 
				
			||||||
 | 
					    <option name="ACTIVE_PROFILES" />
 | 
				
			||||||
 | 
					    <module name="microservice-gateway" />
 | 
				
			||||||
 | 
					    <option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.Gateway" />
 | 
				
			||||||
 | 
					    <extension name="coverage">
 | 
				
			||||||
 | 
					      <pattern>
 | 
				
			||||||
 | 
					        <option name="PATTERN" value="com.cxyxiaomo.epp.*" />
 | 
				
			||||||
 | 
					        <option name="ENABLED" value="true" />
 | 
				
			||||||
 | 
					      </pattern>
 | 
				
			||||||
 | 
					    </extension>
 | 
				
			||||||
 | 
					    <method v="2">
 | 
				
			||||||
 | 
					      <option name="Make" enabled="true" />
 | 
				
			||||||
 | 
					    </method>
 | 
				
			||||||
 | 
					  </configuration>
 | 
				
			||||||
 | 
					</component>
 | 
				
			||||||
@@ -27,6 +27,7 @@
 | 
				
			|||||||
            <groupId>org.springframework.cloud</groupId>
 | 
					            <groupId>org.springframework.cloud</groupId>
 | 
				
			||||||
            <artifactId>spring-cloud-starter-gateway</artifactId>
 | 
					            <artifactId>spring-cloud-starter-gateway</artifactId>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
 | 
					        <!--客户端负载均衡loadbalancer-->
 | 
				
			||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
            <groupId>org.springframework.cloud</groupId>
 | 
					            <groupId>org.springframework.cloud</groupId>
 | 
				
			||||||
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
 | 
					            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.controller;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RequestMapping;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RestController;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@RestController
 | 
				
			||||||
 | 
					public class Controller {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @RequestMapping("/error")
 | 
				
			||||||
 | 
					    public String error() {
 | 
				
			||||||
 | 
					        return "[ERROR] 500 Internal Server Error";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -15,7 +15,27 @@ spring:
 | 
				
			|||||||
          enabled: true
 | 
					          enabled: true
 | 
				
			||||||
          lower-case-service-id: true
 | 
					          lower-case-service-id: true
 | 
				
			||||||
      routes:
 | 
					      routes:
 | 
				
			||||||
        - id: test
 | 
					        - id: test1
 | 
				
			||||||
          uri: lb://microservice-provider-test-8011
 | 
					          uri: lb://microservice-provider-test
 | 
				
			||||||
          predicates:
 | 
					          predicates:
 | 
				
			||||||
            - Path=/test/**
 | 
					            - Path=/test/**,/test1/**
 | 
				
			||||||
 | 
					            - Method=GET,POST
 | 
				
			||||||
 | 
					          filters:
 | 
				
			||||||
 | 
					            - StripPrefix=1 # 跳过第一段 /test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        - id: test2
 | 
				
			||||||
 | 
					          uri: lb://microservice-provider-test
 | 
				
			||||||
 | 
					          predicates:
 | 
				
			||||||
 | 
					            - Path=/test2/{routes}
 | 
				
			||||||
 | 
					          filters:
 | 
				
			||||||
 | 
					            - SetPath=/hi/{routes}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        - id: test3
 | 
				
			||||||
 | 
					          uri: lb://microservice-provider-test
 | 
				
			||||||
 | 
					          predicates:
 | 
				
			||||||
 | 
					            - Path=/test3/**
 | 
				
			||||||
 | 
					          filters:
 | 
				
			||||||
 | 
					            - name: RedirectTo
 | 
				
			||||||
 | 
					              args:
 | 
				
			||||||
 | 
					                status: 302
 | 
				
			||||||
 | 
					                url: https://www.baidu.com/?wd=
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ package com.cxyxiaomo.epp.controller;
 | 
				
			|||||||
// 提供 restful 服务
 | 
					// 提供 restful 服务
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.web.bind.annotation.GetMapping;
 | 
					import org.springframework.web.bind.annotation.GetMapping;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.PathVariable;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RestController;
 | 
					import org.springframework.web.bind.annotation.RestController;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@RestController
 | 
					@RestController
 | 
				
			||||||
@@ -11,4 +12,14 @@ public class TestController {
 | 
				
			|||||||
    public String helloWorld() {
 | 
					    public String helloWorld() {
 | 
				
			||||||
        return "Hello World!";
 | 
					        return "Hello World!";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @GetMapping("/error")
 | 
				
			||||||
 | 
					    public String error() throws Exception {
 | 
				
			||||||
 | 
					        throw new Exception("这是一个异常");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @GetMapping("/hi/{id}")
 | 
				
			||||||
 | 
					    public String hi(@PathVariable("id") String id) {
 | 
				
			||||||
 | 
					        return id;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user