当前位置:网站首页>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/** # 放行靜態資源路徑
边栏推荐
- 迪赛智慧数——柱状图(折柱混合图):2021年毕业季租房价格和房租收入比
- MFC CString to LPVOID
- A low-cost method to increase private domain traffic with simple maintenance
- 【历史上的今天】6 月 17 日:术语“超文本”的创造者出生;Novell 首席科学家诞生;探索频道开播
- Which securities platform is the best and safest for a novice to open a stock trading account
- 【历史上的今天】6 月 12 日:美国进入数字化电视时代;Mozilla 的最初开发者出生;3Com 和美国机器人公司合并
- ByteDance Interviewer: how to calculate the memory size occupied by a picture
- [today in history] June 16: Oracle Bone Inscriptions was established; Microsoft MSX was born; The inventor of fast Fourier transform was born
- What if win11 can't drag an image to the taskbar software to open it quickly
- Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch
猜你喜欢

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

> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复

Design e-commerce seckill system

You got 8K in the 3-year function test, but were overtaken by the new tester. In fact, you are pretending to work hard

迪赛智慧数——柱状图(折柱混合图):2021年毕业季租房价格和房租收入比

2-5基础配置-Win2003增加攻击面

【二维码图像矫正增强】基于MATLAB的二维码图像矫正增强处理仿真

Moving Tencent to the cloud: half of the evolution history of cloud server CVM

How to enable multi language text suggestions? Win11 method to open multilingual text suggestions

【模糊神经网络】基于matlab的模糊神经网络仿真
随机推荐
Which securities platform is the best and safest for a novice to open a stock trading account
【倒立摆控制】基于UKF无迹卡尔曼滤波的倒立摆控制simulink仿真
3年功能测试拿8K,被刚来的测试员反超,其实你在假装努力
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
[today in history] June 18: JD was born; The online store platform Etsy was established; Facebook releases Libra white paper
【历史上的今天】5 月 31 日:Amiga 之父诞生;BASIC 语言的共同开发者出生;黑莓 BBM 停运
Win11不能拖拽圖片到任務欄軟件上快速打開怎麼辦
MFC常用 当前路径
第一次使用gcc和makefile编写c程序
Design e-commerce seckill system
数仓的字符截取三胞胎:substrb、substr、substring
Raspberry pie - environment settings and cross compilation
Stm32f1 and stm32subeide programming example - metal touch sensor driver
[inverted pendulum control] Simulink simulation of inverted pendulum control based on UKF unscented Kalman filter
【历史上的今天】6 月 17 日:术语“超文本”的创造者出生;Novell 首席科学家诞生;探索频道开播
Arduino Esp8266 Web LED控制
Flutter 使用 CustomPaint 绘制基本图形
【Kotlin】在Android官方文档中对其语法的基本介绍和理解
[today in history] June 19: iPhone 3GS launched; Pascal was born; Anti terrorist elite begins testing
Is it safe for qiniu to open an account? How do I open an account online?

