当前位置:网站首页>Gateway微服务路由使微服务静态资源加载失败
Gateway微服务路由使微服务静态资源加载失败
2022-06-28 01:09:00 【云梦归遥】
Gateway微服务路由使微服务静态资源加载失败
1.Gateway
1.1 Gateway介绍
- Gateway就是网关微服务,为我们的各个微服务集群提供一个统一的入口,根据路由匹配进行断言,进行对应微服务的访问
2.Gateway 成功之前和之后
2.1 静态资源失败场景重现
- 远程微服务页面上引入的静态资源路径,/css/index.css
<!-- 引入外部 样式文件 -->
<link rel="stylesheet" type="text/css" href="../static/css/index.css" th:href="@{/css/index.css}">

- 远程微服务放行静态资源,修改配置文件
spring:
application:
name: ProductPageDemo
# 放行静态资源
resources:
static-locations: classpath:/static/
- Gateway网关配置文件
server:
port: 80
spring:
application:
name: GatewayDemo
cloud:
gateway:
# 配置路由
routes:
- id: ProductPageDemo
uri: http://ProductPageDemo:9100
predicates:
# 断言,以 /page/ 开头进行匹配
- Path=/page/**
filters:
# 过滤器,会去除第一级路径然后进行路由
- StripPrefix=1
2.2 修改成功,成功加载
- 因为我的路由匹配需要除去第一级匹配路径,所以我们需要在 对应微服务引入静态资源的时候修改静态资源路径,/page/css/index.css
<!-- 引入外部 样式文件 -->
<link rel="stylesheet" type="text/css" href="../static/css/index.css" th:href="@{/page/css/index.css}">
2.3 如果没有去除第一级路径,大家可以如下配置
server:
port: 80
spring:
application:
name: GatewayDemo
cloud:
gateway:
# 配置路由
routes:
- id: ProductPageDemo
uri: http://ProductPageDemo:9100
predicates:
# 断言,以 /page/ 开头进行匹配
- Path=/page/**,/css/** # 放行静态资源路径
边栏推荐
- Interpretation of bilstm-crf in NER forward_ algorithm
- 【云原生】-Docker安装部署分布式数据库 OceanBase
- 【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形
- Win11不能拖拽图片到任务栏软件上快速打开怎么办
- The graduation season is coming, and the number of college graduates in 2022 has exceeded 10 million for the first time
- 横向滚动的RecycleView一屏显示五个半,低于五个平均分布
- How to judge that the thread pool has completed all tasks?
- Online JSON to plaintext tool
- Get 5 offers after being notified of layoffs
- [today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born
猜你喜欢

Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch
![[today in history] June 6: World IPv6 launch anniversary; Tetris release; Little red book established](/img/06/895913d2c54b03cde86b3116955a9e.png)
[today in history] June 6: World IPv6 launch anniversary; Tetris release; Little red book established
![[today in history] June 15: the first mobile phone virus; AI master simahe was born; Chromebook launch](/img/d4/413c84a75f16a09867cfaa3d7f8736.png)
[today in history] June 15: the first mobile phone virus; AI master simahe was born; Chromebook launch
![[today in history] May 29: the pioneer of sharing software was born; Chromebox launched; VoodooPC founder was born](/img/ba/aa5db22e1391886a4e263d10e5f9f7.png)
[today in history] May 29: the pioneer of sharing software was born; Chromebox launched; VoodooPC founder was born
![[today in history] June 17: the creator of the term](/img/00/30ccc2f54415a6aca000c42e277dc3.png)
[today in history] June 17: the creator of the term "hypertext" was born; The birth of Novell's chief scientist; Discovery channel on
![[today in history] June 10: Apple II came out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word](/img/0d/9f99eb3dcb73c912987b81fba71890.png)
[today in history] June 10: Apple II came out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born

Character interception triplets of data warehouse: substrb, substr, substring

【历史上的今天】6 月 25 日:笔记本之父诞生;Windows 98 发布;通用产品代码首次商用
![[today in history] June 7: kubernetes open source version was released; Worldofwarcraft landed in China; Birth of the inventor of packet switching network](/img/70/6864b41e17502ec391db23ae83bd4b.png)
[today in history] June 7: kubernetes open source version was released; Worldofwarcraft landed in China; Birth of the inventor of packet switching network

【历史上的今天】6 月 15 日:第一个手机病毒;AI 巨匠司马贺诞生;Chromebook 发布
随机推荐
Online text batch inversion by line tool
Unity WebGL打包后怎么运行(火狐配置)
Win11不能拖拽圖片到任務欄軟件上快速打開怎麼辦
Prometheus 2.27.0 new features
NER中BiLSTM-CRF解读Forward_algorithm
[today in history] June 8: the father of the world wide web was born; PHP public release; IPhone 4 comes out
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
[today in history] June 7: kubernetes open source version was released; Worldofwarcraft landed in China; Birth of the inventor of packet switching network
面试:Bitmap像素内存分配在堆内存还是在native中
win11如何添加打印机和扫描仪?win11添加打印机和扫描仪的设置
初始线性回归
How to enable multi language text suggestions? Win11 method to open multilingual text suggestions
[today in history] June 3: Microsoft launched Bing search engine; Larry Roberts starts ARPANET; The father of Visual Basic was born
【二维码图像矫正增强】基于MATLAB的二维码图像矫正增强处理仿真
【历史上的今天】6 月 10 日:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world
【历史上的今天】6 月 19 日:iPhone 3GS 上市;帕斯卡诞生;《反恐精英》开始测试
【历史上的今天】6 月 20 日:MP3 之父出生;富士通成立;谷歌收购 Dropcam
Digital intelligence learning Lake Warehouse Integration Practice and exploration
【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形

