网关开发
This commit is contained in:
parent
ee4dcde935
commit
f862d7503b
@ -11,6 +11,23 @@
|
|||||||
|
|
||||||
<artifactId>xdclass-gateway</artifactId>
|
<artifactId>xdclass-gateway</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- <!–添加nacos客户端–>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.alibaba.cloud</groupId>-->
|
||||||
|
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!--配置中心-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.jieyuu;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@SpringBootApplication
|
||||||
|
public class GatewayApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(GatewayApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
57
xdclass-gateway/src/main/resources/application.yml
Normal file
57
xdclass-gateway/src/main/resources/application.yml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
server:
|
||||||
|
port: 8889
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: api-gateway
|
||||||
|
cloud:
|
||||||
|
#注册中心地址
|
||||||
|
nacos:
|
||||||
|
discoveru:
|
||||||
|
server-addr: 8.134.32.140:8848
|
||||||
|
|
||||||
|
gateway:
|
||||||
|
routes: #数组形式
|
||||||
|
- id: product-service #商品服务 路由唯一标识
|
||||||
|
uri: lb://xdclass-product-service #从nocas进行转发
|
||||||
|
order: 1 #优先级,数字越小优先级越高
|
||||||
|
predicates: #断言 配置哪个路径才转发,前端访问路径统一加上XXX-server,网关判断转发对应的服务,如果是回调业务记得修改
|
||||||
|
- Path=/product-server/**
|
||||||
|
filters: #过滤器,请求在传递过程中通过过滤器修改
|
||||||
|
- StripPrefix=1 #去掉第一层前缀,转发给后续的路径
|
||||||
|
|
||||||
|
- id: user-service #用户服务 路由唯一标识
|
||||||
|
uri: lb://xdclass-user-service #从nocas进行转发
|
||||||
|
order: 2 #优先级,数字越小优先级越高
|
||||||
|
predicates: #断言 配置哪个路径才转发,前端访问路径统一加上XXX-server,网关判断转发对应的服务,如果是回调业务记得修改
|
||||||
|
- Path=/user-service/**
|
||||||
|
filters: #过滤器,请求在传递过程中通过过滤器修改
|
||||||
|
- StripPrefix=1 #去掉第一层前缀,转发给后续的路径
|
||||||
|
|
||||||
|
- id: coupon-service #商品服务 路由唯一标识
|
||||||
|
uri: lb://xdclass-coupon-service #从nocas进行转发
|
||||||
|
order: 3 #优先级,数字越小优先级越高
|
||||||
|
predicates: #断言 配置哪个路径才转发,前端访问路径统一加上XXX-server,网关判断转发对应的服务,如果是回调业务记得修改
|
||||||
|
- Path=/coupon-server/**
|
||||||
|
filters: #过滤器,请求在传递过程中通过过滤器修改
|
||||||
|
- StripPrefix=1 #去掉第一层前缀,转发给后续的路径
|
||||||
|
|
||||||
|
- id: order-service #商品服务 路由唯一标识
|
||||||
|
uri: lb://xdclass-order-service #从nocas进行转发
|
||||||
|
order: 3 #优先级,数字越小优先级越高
|
||||||
|
predicates: #断言 配置哪个路径才转发,前端访问路径统一加上XXX-server,网关判断转发对应的服务,如果是回调业务记得修改
|
||||||
|
- Path=/order-server/**
|
||||||
|
filters: #过滤器,请求在传递过程中通过过滤器修改
|
||||||
|
- StripPrefix=1 #去掉第一层前缀,转发给后续的路径
|
||||||
|
|
||||||
|
#开启网关拉取nacos的服务
|
||||||
|
discovery:
|
||||||
|
locator:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
#设置日志级别,ERROR/WARN/INFO/DEBUG,默认是INFO以上才显示
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
root: INFO
|
||||||
|
#nacos日志问题
|
||||||
|
com.alibaba.nacos.client.config.impl: WARN
|
6
xdclass-gateway/src/main/resources/bootstrap.yml
Normal file
6
xdclass-gateway/src/main/resources/bootstrap.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
#注册中心地址
|
||||||
|
nacos:
|
||||||
|
config:
|
||||||
|
server-addr: 8.134.32.140:8848
|
Loading…
Reference in New Issue
Block a user