1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

Gateway配置文件

This commit is contained in:
程序员小墨 2022-11-06 00:18:46 +08:00
parent 529ef7528e
commit 7ec7fc1e4f
6 changed files with 68 additions and 3 deletions

View File

@ -283,6 +283,10 @@ Spring initializrhttps://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
##### Gateway
B站教程https://www.bilibili.com/video/BV1JB4y1F7aL
#### Maven
MVN REPOSITORYhttps://mvnrepository.com/

View 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>

View File

@ -27,6 +27,7 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!--客户端负载均衡loadbalancer-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>

View File

@ -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";
}
}

View File

@ -15,7 +15,27 @@ spring:
enabled: true
lower-case-service-id: true
routes:
- id: test
uri: lb://microservice-provider-test-8011
- id: test1
uri: lb://microservice-provider-test
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=

View File

@ -3,6 +3,7 @@ package com.cxyxiaomo.epp.controller;
// 提供 restful 服务
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
@ -11,4 +12,14 @@ public class TestController {
public String helloWorld() {
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;
}
}