iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >解决spring boot网关gateway导致的坑,无法下载文件问题
  • 162
分享到

解决spring boot网关gateway导致的坑,无法下载文件问题

2024-04-02 19:04:59 162人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

话不多说,直接上图 接口返回内容,浏览器显示pdf文档。但是输入接口地址以后一直提示这个 核对接口路径也是正确的,并且没有报错提示,后面发现是网关没有配置放行路径,于是进行了补充

话不多说,直接上图

接口返回内容,浏览器显示pdf文档。但是输入接口地址以后一直提示这个

核对接口路径也是正确的,并且没有报错提示,后面发现是网关没有配置放行路径,于是进行了补充

所以 以后对于前端请求统一由网关进行配置处理的,一定要对于静态资源合理配置,或者对于放行接口要统一补充进来(最后统一一下下接口前缀名称,这样就只需要写一个了)

下面我再说一个坑:

spring cloud gateway启动报错:org.springframework.cloud.gateway.config.GatewayAutoConfiguration

SpringCloud 启动一直报错 详细错误信息

Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.Http.codec.ServerCodecConfigurer' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.

解决办法

将pom文件中的spring-boot-starter-WEB 移除

详细分析

点进去 GatewayAutoConfiguration 这个类


@Bean
public ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory(ServerCodecConfigurer codecConfigurer) {
    return new ModifyRequestBodyGatewayFilterFactory(codecConfigurer.getReaders());
}

@Bean
public DedupeResponseHeaderGatewayFilterFactory dedupeResponseHeaderGatewayFilterFactory() {
    return new DedupeResponseHeaderGatewayFilterFactory();
}

@Bean
public ModifyResponseBodyGatewayFilterFactory modifyResponseBodyGatewayFilterFactory(ServerCodecConfigurer codecConfigurer, Set<MessageBodyDecoder> bodyDecoders, Set<MessageBodyEncoder> bodyEncoders) {
    return new ModifyResponseBodyGatewayFilterFactory(codecConfigurer.getReaders(), bodyDecoders, bodyEncoders);
}

确实需要这个bean

spring cloud gateway server项目是一个Spring Boot项目,在启动的时候会去加载它的配置,其中有一个叫做GatewayClassPathWarningAutoConfiguration的配置类 代码入下


@Configuration(
    proxyBeanMethods = false
)
//在 GatewayAutoConfiguration 执行执行 
@AutoConfigureBefore({GatewayAutoConfiguration.class})
public class GatewayClassPathWarningAutoConfiguration {
    private static final Log log = LogFactory.getLog(GatewayClassPathWarningAutoConfiguration.class);
    private static final String BORDER = "\n\n**********************************************************\n\n";
    public GatewayClassPathWarningAutoConfiguration() {
    }

    @Configuration(
        proxyBeanMethods = false
    )
    @ConditionalOnMissinGClass({"org.springframework.web.Reactive.DispatcherHandler"})
    protected static class WebfluxMissingFromClasspathConfiguration {
        public WebfluxMissingFromClasspathConfiguration() {
            GatewayClassPathWarningAutoConfiguration.log.warn("\n\n**********************************************************\n\nSpring Webflux is missing from the classpath, which is required for Spring Cloud Gateway at this time. Please add spring-boot-starter-webflux dependency.\n\n**********************************************************\n\n");
        }
    }

    @Configuration(
        proxyBeanMethods = false
    )
    @ConditionalOnClass(
        name = {"org.springframework.web.servlet.DispatcherServlet"}
    )
    protected static class springMVCFoundOnClasspathConfiguration {
        public SpringmvcFoundOnClasspathConfiguration() {
            GatewayClassPathWarningAutoConfiguration.log.warn("\n\n**********************************************************\n\nSpring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.\n\n**********************************************************\n\n");
        }
    }
}

我们pom中依赖了spring-boot-starter-web 也就是存在


org.springframework.web.servlet.DispatcherServlet

此时这个 与Spring Cloud Gateway不兼容

spring cloud gateway是基于webflux的,如果需要web支持的话需要导入spring-boot-starter-webflux取代spring-boot-start-web。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: 解决spring boot网关gateway导致的坑,无法下载文件问题

本文链接: https://www.lsjlt.com/news/130613.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作