当前位置:网站首页>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/** # 放行静态资源路径
边栏推荐
- Usage details of staticlayout
- [cloud native] - docker installation and deployment of distributed database oceanbase
- 把腾讯搬上云:云服务器 CVM 的半部进化史
- JDBC与MySQL数据库
- MFC common current path
- Packet capturing and sorting out external Fiddler -- understanding the toolbar [1]
- JDBC and MySQL databases
- [fuzzy neural network] simulation of fuzzy neural network based on MATLAB
- [today in history] June 2: Apple launched swift programming language; China Telecom acquires China Unicom C network; OS X Yosemite release
- 初始线性回归
猜你喜欢

字节跳动面试官:一张图片占据的内存大小是如何计算
![[today in history] June 1: Napster was founded; MS-DOS original author was born; Google sells Google SketchUp](/img/fe/497eab2ac4a762298e71d28ed26e41.png)
[today in history] June 1: Napster was founded; MS-DOS original author was born; Google sells Google SketchUp
![[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](/img/91/d7d6137b95f6348f71692164614340.png)
[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

数据清洗工具flashtext,效率直接提升了几十倍数
![[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

【历史上的今天】6 月 10 日:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生
![[today in history] June 8: the father of the world wide web was born; PHP public release; IPhone 4 comes out](/img/1b/31b5adbec5182207c371a23e41baa3.png)
[today in history] June 8: the father of the world wide web was born; PHP public release; IPhone 4 comes out

Win11 ne peut pas faire glisser l'image sur le logiciel de la barre des tâches

在线文本按行批量反转工具

Design e-commerce seckill system
随机推荐
Win11 ne peut pas faire glisser l'image sur le logiciel de la barre des tâches
【模糊神经网络】基于matlab的模糊神经网络仿真
无心剑英汉双语诗004.《静心》
把腾讯搬上云:云服务器 CVM 的半部进化史
Arduino Esp8266 Web LED控制
Writing based on stm32
Packet capturing and sorting out external Fiddler -- understanding the toolbar [1]
无心剑汉英双语诗004.《剑》
面试:List 如何根据对象的属性去重?
Online JSON to plaintext tool
MFC CString互转LPVOID
榜单首发——前装搭载率站上10%大关,数字钥匙方案供应商TOP10
【历史上的今天】6 月 10 日:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生
Mysql database foundation: DML data operation language
树莓派-环境设置和交叉编译
win11如何添加打印机和扫描仪?win11添加打印机和扫描仪的设置
[today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born
【历史上的今天】5 月 31 日:Amiga 之父诞生;BASIC 语言的共同开发者出生;黑莓 BBM 停运
【历史上的今天】6 月 5 日:洛夫莱斯和巴贝奇相遇;公钥密码学先驱诞生;函数语言设计先驱出生
[elevator control system] design of elevator control system based on VHDL language and state machine, using state machine

