当前位置:网站首页>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/** # 放行静态资源路径
边栏推荐
- Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch
- Unity WebGL打包后怎么运行(火狐配置)
- 【电梯控制系统】基于VHDL语言和状态机实现的电梯控制系统的设计,使用了状态机
- Publicity of the third batch of shortlisted enterprises! Annual Top100 smart network supplier selection
- How to realize red, green and yellow traffic lights in ros+gazebo?
- 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
- Win11如何关闭最近打开项目?Win11关闭最近打开项目的方法
- The horizontal scrolling recycleview displays five and a half in one screen, which is lower than the five average distributions
- 批阅2022春季学期课程小论文提交情况
- Interview: how do lists duplicate objects according to their attributes?
猜你喜欢

isEmpty 和 isBlank 的用法區別

第一次使用gcc和makefile编写c程序

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

What if win11 can't drag an image to the taskbar software to open it quickly

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

ByteDance Interviewer: how to calculate the memory size occupied by a picture
![抓包整理外篇fiddler————了解工具栏[一]](/img/5f/24fd110a73734ba1638f0aad63c787.png)
抓包整理外篇fiddler————了解工具栏[一]
![[inverted pendulum control] Simulink simulation of inverted pendulum control based on UKF unscented Kalman filter](/img/17/3c93ddf8f55c63a97480a78cbf8111.png)
[inverted pendulum control] Simulink simulation of inverted pendulum control based on UKF unscented Kalman filter

Intel Ruixuan A380 graphics card will be launched in China

How does win11 add printers and scanners? Win11 add printer and scanner settings
随机推荐
[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
如何判断线程池已经执行完所有任务了?
3年功能测试拿8K,被刚来的测试员反超,其实你在假装努力
Interview: is bitmap pixel memory allocated in heap memory or native
【历史上的今天】6 月 12 日:美国进入数字化电视时代;Mozilla 的最初开发者出生;3Com 和美国机器人公司合并
【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形
数据清洗工具flashtext,效率直接提升了几十倍数
批阅2022春季学期课程小论文提交情况
【历史上的今天】6 月 16 日:甲骨文成立;微软 MSX 诞生;快速傅里叶变换发明者出生
2-5基础配置-Win2003增加攻击面
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
CRF+BiLSTM代码分步骤解读
How to enable multi language text suggestions? Win11 method to open multilingual text suggestions
【历史上的今天】6 月 11 日:蒙特卡罗方法的共同发明者出生;谷歌推出 Google 地球;谷歌收购 Waze
Moving Tencent to the cloud: half of the evolution history of cloud server CVM
A low-cost method to increase private domain traffic with simple maintenance
SQL报了一个不常见的错误,让新来的实习生懵了
Différences d'utilisation entre IsEmpty et isblank
Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch
【插件-statistic】统计代码行数和相关数据

