当前位置:网站首页>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/** # 放行靜態資源路徑
边栏推荐
- Writing C program with GCC and makefile for the first time
- [today in history] June 25: the father of notebook was born; Windows 98 release; First commercial use of generic product code
- 横向滚动的RecycleView一屏显示五个半,低于五个平均分布
- 微信小程序中生成二维码
- 【二维码图像矫正增强】基于MATLAB的二维码图像矫正增强处理仿真
- 【方块编码】基于matlab的图像方块编码仿真
- How to judge that the thread pool has completed all tasks?
- 基于STM32的编写
- MFC常用 当前路径
- 【二維碼圖像矯正增强】基於MATLAB的二維碼圖像矯正增强處理仿真
猜你喜欢
![[today in history] June 16: Oracle Bone Inscriptions was established; Microsoft MSX was born; The inventor of fast Fourier transform was born](/img/4f/67e1598b523058a8fb6f3148136902.png)
[today in history] June 16: Oracle Bone Inscriptions was established; Microsoft MSX was born; The inventor of fast Fourier transform was born
![[today in history] June 20: the father of MP3 was born; Fujitsu was established; Google acquires dropcam](/img/54/df623fc1004e1dca5d369b4ed2608c.png)
[today in history] June 20: the father of MP3 was born; Fujitsu was established; Google acquires dropcam

【历史上的今天】5 月 31 日:Amiga 之父诞生;BASIC 语言的共同开发者出生;黑莓 BBM 停运

Usage details of staticlayout
![[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](/img/2c/01e3be3c5b4f8e6a7853547ffd1bbd.png)
[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

【历史上的今天】6 月 8 日:万维网之父诞生;PHP 公开发布;iPhone 4 问世

Online text batch inversion by line tool

转载文章:数字经济催生强劲算力需求 英特尔发布多项创新技术挖掘算力潜能

【历史上的今天】5 月 29 日:共享软件先驱诞生;ChromeBox 推出;VoodooPC 创始人出生

【历史上的今天】6 月 19 日:iPhone 3GS 上市;帕斯卡诞生;《反恐精英》开始测试
随机推荐
【二維碼圖像矯正增强】基於MATLAB的二維碼圖像矯正增强處理仿真
如何开启多语言文本建议?Win11打开多语言文本建议的方法
面试:List 如何根据对象的属性去重?
Win11新建不了文本文档?Win11右键无法新建文本文档的解决方法
【历史上的今天】6 月 19 日:iPhone 3GS 上市;帕斯卡诞生;《反恐精英》开始测试
【云原生】-Docker安装部署分布式数据库 OceanBase
[today in history] June 12: the United States entered the era of digital television; Mozilla's original developer was born; 3com merges with American Robotics
Mixed programming of C language and assembly language in stm32
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
LiveData 面试题库、解答---LiveData 面试 7 连问~
[today in history] June 20: the father of MP3 was born; Fujitsu was established; Google acquires dropcam
Flutter 使用 CustomPaint 绘制基本图形
[cloud native] - docker installation and deployment of distributed database oceanbase
Reprinted article: the digital economy generates strong demand for computing power Intel releases a number of innovative technologies to tap the potential of computing power
Why are so many people keen on big factories because of the great pressure and competition?
CRF+BiLSTM代码分步骤解读
《天天数学》连载53:二月二十一日
【二维码图像矫正增强】基于MATLAB的二维码图像矫正增强处理仿真
SQL reported an unusual error, which confused the new interns
[today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born

