springcloud项目 网关demo
其他服务的地址
https://blog.csdn.net/weixin_45730866/article/details/128932291?spm=1001.2014.3001.5501
导依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
配置文件
server:
port: 9999
spring:
application:
name: gateway
cloud:
nacos:
discovery:
server-addr: localhost:8848
gateway:
discovery:
locator:
enabled: true #是否与服务注册于发现组件结合,通过 serviceId 转发到具体的服务
lower-case-service-id: true
routes:
- id: gateway-service-consumer-order
uri: lb://consumer-order
predicates:
- Path=/provider/**
启动类加@EnableDiscoveryClient注解即可,启动访问http://127.0.0.1:9999/consumer-order/order/getOrder
项目地址:https://gitee.com/lideru/springboot-cloud-nacos