依赖文件在项目搭建时已经添加,这里进行完善
配置文件
新建bootstrap.yaml
配置文件,内容如下:
|
Nacos配置文件
ID:trip-gateway-dev.yaml
Group:DEFAULT_GROUP
描述:旅游项目网关配置
配置内容:
feign-dev.yaml server:
port: 9000
spring:
cloud:
nacos:
server-addr: 124.221.23.47:8848
discovery:
namespace: ${spring.cloud.nacos.config.namespace}
gateway:
discovery:
locator:
enabled: true
globalcors:
cors-configurations:
'[/**]':
allowedOrigins: "*"
allowedMethods:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
allowedHeaders: "*"
allowCredentials: true
routes:
- id: trip_user
uri: lb://user-service
predicates:
- Path=/users/**
- Path=/sms/**
启动类
创建包com.swx.gateway
,创建启动类 TripGatewayApplication
|
启动时,需要先启动Nacos