线上的配置
spring:cloud:gateway:routes:# ws表示websocket的转发- id: test-websocketuri: ws://127.0.0.1:9006predicates:- Path=/ws/**filters:- StripPrefix=1# ws表示websocket的转发- id: nocas-websocketuri: ws://test-websocketpredicates:- Path=/ser/ws/**filters:- StripPrefix=2- id: api-websocketuri: lb://test-websocketpredicates:- Path=/api/**filters:- StripPrefix=1# ws表示websocket的转发- id: test-websocket2uri: ws://127.0.0.1:9007predicates:- Path=/ws2/**filters:- StripPrefix=1# ws表示websocket的转发 - 这是错误的- id: nocas-websocket2uri: ws://test-websocket2predicates:- Path=/ser2/ws/**filters:- StripPrefix=2- id: nocas2-websocket2uri: lb:ws://test-websocket2predicates:- Path=/serlb/ws/**filters:- StripPrefix=2- id: api-websocket2uri: lb://test-websocket2predicates:- Path=/api2/**filters:- StripPrefix=1
线下可以的配置 ```yaml server: port: 9005
spring: main: allow-bean-definition-overriding: true
profiles:
active: socket
application: name: gateway cloud: nacos: discovery: server-addr: 127.0.0.1:8848 # 注册中心 group: websocket namespace: f5b7faf1-58b9-4365-b366-3893c470a208 config: server-addr: 127.0.0.1:8848 # 配置中心 namespace: f5b7faf1-58b9-4365-b366-3893c470a208 group: websocket file-extension: yaml #文件扩展名格式,针对于默认的{spring.application.name}-${profile}.${file-extension:properties}配置 enabled: true #开启或关闭配置中心 gateway: discovery: locator: enabled: true # 开启基于服务的注册和发现 的 路由转发,默认轮询模式 globalcors: corsConfigurations: ‘[/*]’: allowedHeaders: ““ allowedOrigins: ““ allowedMethods: ““
配置这一项可以监控gateway各个节点的信息
management: endpoints: web: exposure: include: gateway
3. 线下不可行的配置```yamlserver:port: 9005spring:application:name: test-gatewaycloud:nacos:discovery:server-addr: 127.0.0.1:8848 # 注册中心group: websocketnamespace: f5b7faf1-58b9-4365-b366-3893c470a208config:server-addr: 127.0.0.1:8848 # 配置中心group: websocketfile-extension: yaml #文件扩展名格式,针对于默认的{spring.application.name}-${profile}.${file-extension:properties}配置enabled: true #开启或关闭配置中心namespace: f5b7faf1-58b9-4365-b366-3893c470a208#路由配置,user-service是我的服务名gateway:discovery:locator:enabled: true# lower-case-service-id: trueglobalcors:corsConfigurations:'[/**]':allowedHeaders: "*"allowedOrigins: "*"allowedMethods: "*"management:endpoints:web:exposure:include: gateway
- 对比之后发现这个错误真无语
- srping.application.name=gateway ( - ) srping.application.name=test-gateway
- application.name的名字要跟线上的yaml名字一样。既


