当前位置:网站首页>Gateway微服務路由使微服務靜態資源加載失敗
Gateway微服務路由使微服務靜態資源加載失敗
2022-06-28 02:56: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/** # 放行靜態資源路徑
边栏推荐
- [today in history] June 20: the father of MP3 was born; Fujitsu was established; Google acquires dropcam
- 新手炒股开户选哪家证券平台办理是最好最安全的
- Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times
- Win11 ne peut pas faire glisser l'image sur le logiciel de la barre des tâches
- [today in history] June 23: Turing's birthday; The birth of the founder of the Internet; Reddit goes online
- 【二维码图像矫正增强】基于MATLAB的二维码图像矫正增强处理仿真
- Raspberry pie - environment settings and cross compilation
- 抓包整理外篇fiddler————了解工具栏[一]
- [today in history] June 2: Apple launched swift programming language; China Telecom acquires China Unicom C network; OS X Yosemite release
- 如何开启多语言文本建议?Win11打开多语言文本建议的方法
猜你喜欢

How does win11 add printers and scanners? Win11 add printer and scanner settings

The first place on the list - the carrying rate of front-end equipment is up to 10%, and the top 10 suppliers of digital key solutions
![[today in history] June 3: Microsoft launched Bing search engine; Larry Roberts starts ARPANET; The father of Visual Basic was born](/img/9e/408ae022d9d5d8106e94e71b319d43.png)
[today in history] June 3: Microsoft launched Bing search engine; Larry Roberts starts ARPANET; The father of Visual Basic was born

> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair

在线文本按行批量反转工具
![[cloud native] - docker installation and deployment of distributed database oceanbase](/img/02/57ab785acafd8ff0a49c584dd05188.png)
[cloud native] - docker installation and deployment of distributed database oceanbase

Win11 cannot create a new text document? Solution to win11 right click failure to create a new text document

【倒立摆控制】基于UKF无迹卡尔曼滤波的倒立摆控制simulink仿真

【历史上的今天】6 月 19 日:iPhone 3GS 上市;帕斯卡诞生;《反恐精英》开始测试
![[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
随机推荐
Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch
第一次使用gcc和makefile编写c程序
Summary of software testing tools in 2021 - fuzzy testing tools
2021年软件测试工具总结——模糊测试工具
Online text batch inversion by line tool
Win11 cannot create a new text document? Solution to win11 right click failure to create a new text document
Online JSON to plaintext tool
MFC常用 当前路径
无心剑英汉双语诗004.《静心》
Digital intelligence learning Lake Warehouse Integration Practice and exploration
[today in history] June 6: World IPv6 launch anniversary; Tetris release; Little red book established
Livedata interview question bank and answers -- 7 consecutive questions for livedata interview~
Stm32f1 and stm32subeide programming example - metal touch sensor driver
[today in history] June 13: parent-child disputes in packet switched networks; The founder of game theory was born; The embryonic form of interactive television
PHP 代码 微信、公众号、企业微信 发送表情符号 [U+1F449]
JDBC与MySQL数据库
Get 5 offers after being notified of layoffs
Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times
How to systematically learn LabVIEW?
毕业季来临,2022届高校毕业生人数首次突破千万大关

