当前位置:网站首页>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/** # 放行靜態資源路徑
边栏推荐
- Get 5 offers after being notified of layoffs
- 树莓派-环境设置和交叉编译
- Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times
- 如何判断线程池已经执行完所有任务了?
- 基于STM32的编写
- StaticLayout的使用详解
- Online text batch inversion by line tool
- [fuzzy neural network] simulation of fuzzy neural network based on MATLAB
- 毕业季来临,2022届高校毕业生人数首次突破千万大关
- Mixed programming of C language and assembly language in stm32
猜你喜欢

基于STM32的编写

Opencv——霍夫变换以及遇到的一些问题

Online text batch inversion by line tool

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

Win11新建不了文本文档?Win11右键无法新建文本文档的解决方法
![[today in history] May 31: the father of Amiga was born; The co developer of basic language was born; BlackBerry BBM shutdown](/img/6e/f0e71bb941d5940dbf6d51b812b52e.png)
[today in history] May 31: the father of Amiga was born; The co developer of basic language was born; BlackBerry BBM shutdown
![[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world](/img/f7/b3239802d19d00f760bb3174649a89.jpg)
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world

How does win11 close recently opened projects? Win11 method to close recently opened projects

【Kotlin】在Android官方文档中对其语法的基本介绍和理解

How to judge that the thread pool has completed all tasks?
随机推荐
Digital intelligence learning Lake Warehouse Integration Practice and exploration
[today in history] May 31: the father of Amiga was born; The co developer of basic language was born; BlackBerry BBM shutdown
简单ELK配置实现生产级别的日志采集和查询实践
"Dadao Zhichuang" won a ten million prea+ round of financing and launched a technology consumption robot
How to run unity webgl after packaging (Firefox configuration)
[today in history] June 2: Apple launched swift programming language; China Telecom acquires China Unicom C network; OS X Yosemite release
Feign远程调用fallback回调失败,无效果
Cloud native (30) | kubernetes' app store Helm
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world
How to systematically learn LabVIEW?
Mysql database foundation: DML data operation language
第三批入围企业公示!年度TOP100智能网联供应商评选
LiveData 面试题库、解答---LiveData 面试 7 连问~
Online text batch inversion by line tool
[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
Which securities platform is the best and safest for a novice to open a stock trading account
[today in history] June 18: JD was born; The online store platform Etsy was established; Facebook releases Libra white paper
【Kotlin】在Android官方文档中对其语法的基本介绍和理解
【历史上的今天】5 月 29 日:共享软件先驱诞生;ChromeBox 推出;VoodooPC 创始人出生
What if win11 cannot use dynamic wallpaper? Solution of win11 without dynamic wallpaper

