iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Springboot+gateway如何整合依赖并处理依赖冲突问题
  • 178
分享到

Springboot+gateway如何整合依赖并处理依赖冲突问题

2023-06-26 03:06:07 178人浏览 八月长安
摘要

本篇内容主要讲解“SpringBoot+gateway如何整合依赖并处理依赖冲突问题”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“springboot+gateway如何整合依赖并处理依赖冲突问

本篇内容主要讲解“SpringBoot+gateway如何整合依赖并处理依赖冲突问题”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习springboot+gateway如何整合依赖并处理依赖冲突问题”吧!

正文

Spring Boot版本和spring cloud版本

框架版本
SpringBoot2.3.12.RELEASE
SpringCloudHoxton.SR1

pom依赖

<parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>2.3.12.RELEASE</version>        <relativePath/>    </parent>    <dependencies>        <!-- spring-boot-starter -->        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter</artifactId>        </dependency>        <!-- gateway与spring-boot-starter-WEB冲突(spring-boot-starter-webflux) -->        <!--<dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>-->        <!-- sprinGCloud gateway -->        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-gateway</artifactId>            <!--<exclusions>                <exclusion>                    <groupId>org.springframework.boot</groupId>                    <artifactId>spring-boot-starter-webflux</artifactId>                </exclusion>            </exclusions>-->        </dependency>        <!-- HttpClient依赖,缺少此依赖api网关转发请求时可能发生503错误 -->        <dependency>            <groupId>org.apache.httpcomponents</groupId>            <artifactId>httpclient</artifactId>            <version>4.5.5</version>        </dependency>    </dependencies>    <dependencyManagement>        <dependencies>            <dependency>                <groupId>org.springframework.cloud</groupId>                <artifactId>spring-cloud-dependencies</artifactId>                <version>Hoxton.SR1</version>                <type>pom</type>                <scope>import</scope>            </dependency>        </dependencies>    </dependencyManagement>

配置文件(application.yml)

server:  port: 8700spring:  application:    name: sca-gateway  cloud:    gateway:      routes: #配置网关路由规则        - id: route01  #路由id,自己指定一个唯一值即可          uri: http://localhost:8081/ #网关帮我们转发的url          predicates: ###断言(谓此):匹配请求规则            - Path=/Nacos/provider/echo/**  #请求路径定义,此路径对应uri中的资源          filters: ##网关过滤器,用于对谓词中的内容进行判断分析以及处理            - StripPrefix=1 #转发之前去掉path中第一层路径,例如nacos

依赖冲突问题

**********************************************************
Spring mvc found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.
**********************************************************
2020-07-21 10:12:27.253  WARN 8576 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayControllerEndpoint' defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration$GatewayActuatorConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayControllerEndpoint' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'modifyRequestBodyGatewayFilterFactory' defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration.class]: Unsatisfied dependency expressed through method 'modifyRequestBodyGatewayFilterFactory' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.http.codec.ServerCodecConfigurer' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2020-07-21 10:12:27.253  INFO 8576 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-07-21 10:12:27.273  INFO 8576 --- [           main] ConditionEvaluationReportLoggingListener : 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-07-21 10:12:27.388 ERROR 8576 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
APPLICATION FAILED TO START
***************************
Description:
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.
2020-07-21 10:12:27.398  WARN 8576 --- [           main] o.s.boot.SpringApplication               : Unable to close ApplicationContext
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springApplicationAdminReGIStrar' defined in class path resource [org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springApplicationAdminRegistrar' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.env.Environment' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:245) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:197) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:134) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:81) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:67) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:167) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:978) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:814) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:325) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at online.hupeng.cloud.gateway.GateWayApplication.main(GateWayApplication.java:12) [classes/:na]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.env.Environment' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1716) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1272) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    ... 23 common frames omitted

注:spring-cloud-starter-gatewayspring-boot-starter-web依赖发生冲突,因为gateway依赖包内置spring-boot-starter-webflux依赖,与web包内的spring-boot-starter-webflux依赖起了冲突。

解决方法

spring-boot-starter-webspring-依赖包剔除,或剔除boot-starter-webflux依赖包。

1. 剔除web包<!-- gateway与spring-boot-starter-web冲突(spring-boot-starter-webflux) --><!--<dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-web</artifactId></dependency>-->1. 剔除webflux包<!-- gateway与spring-boot-starter-web冲突(spring-boot-starter-webflux) --><dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-web</artifactId>     <exclusions>          <exclusion>               <groupId>org.springframework.boot</groupId>               <artifactId>spring-boot-starter-webflux</artifactId>          </exclusion>     </exclusions></dependency>

到此,相信大家对“Springboot+gateway如何整合依赖并处理依赖冲突问题”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

--结束END--

本文标题: Springboot+gateway如何整合依赖并处理依赖冲突问题

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

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

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

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

下载Word文档
猜你喜欢
  • Springboot+gateway如何整合依赖并处理依赖冲突问题
    本篇内容主要讲解“Springboot+gateway如何整合依赖并处理依赖冲突问题”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Springboot+gateway如何整合依赖并处理依赖冲突问...
    99+
    2023-06-26
  • 关于Springboot+gateway整合依赖并处理依赖冲突问题
    正文 spring boot版本和spring cloud版本 框架版本SpringBoot2.3.12.RELEASESpringCloudHoxton.SR1 pom依赖 &l...
    99+
    2024-04-02
  • ubuntu依赖冲突如何处理
    在Ubuntu中,处理依赖冲突的常用方法有以下几种:1. 更新软件源:首先确保系统的软件源是最新的,可以使用以下命令更新软件源:``...
    99+
    2023-09-20
    ubuntu
  • springboot依赖冲突问题及解决过程
    项目场景:  新搭了一个springboot 2.3.7.RELASE的框架,在集成mysql,tkMapper,mybatis的过程中,启动报错。 问题描述: 提示各种依...
    99+
    2024-04-02
  • maven冲突依赖问题如何解决
    Maven冲突依赖问题可以通过以下方法解决: 使用`mvn dependency:tree`命令查看项目的依赖树,找到冲突的依赖...
    99+
    2023-10-27
    maven
  • gradle依赖冲突问题怎么解决
    在Gradle中,依赖冲突通常是由于不同的依赖项引入了相同的库的不同版本造成的。以下是一些解决依赖冲突问题的方法:1. 使用`gra...
    99+
    2023-10-11
    gradle
  • 如何定位、解决maven依赖冲突问题
    目录 1.依赖冲突的原因 2.复现一个依赖冲突场景 3.如何定位依赖冲突 3.1.maven show dependencies 3.2.maven helper 4.依赖路径最短优先原则 1.依赖冲突的原因 如果maven项目中,A依...
    99+
    2023-09-03
    算法 linux 前端 原力计划
  • 如何解决Maven依赖冲突
    今天小编给大家分享的是如何解决Maven依赖冲突,相信很多人都不太了解,为了让大家更加了解,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。目录背景处理回顾背景在项目中screw-core依赖时发生了冲突,控制台指出是log4j...
    99+
    2023-07-06
  • java怎么解决依赖版本冲突问题
    在Java中解决依赖版本冲突问题有以下几种方法: 更新依赖版本:可以尝试更新冲突的依赖版本,看是否有新版本解决了冲突问题。可以通...
    99+
    2023-10-27
    java
  • Mybatis-plus与Mybatis依赖冲突问题解决方法
    错误描述 An attempt was made to call a method that does not exist. The attempt was made from t...
    99+
    2024-04-02
  • maven多版本依赖冲突问题怎么解决
    Maven的多版本依赖冲突问题可以通过以下几种方式解决:1. 排除依赖:在项目的pom.xml文件中,可以使用``标签排除某个依赖的...
    99+
    2023-09-23
    maven
  • linux安装依赖库冲突如何解决
    在Linux上,解决依赖库冲突的方法包括以下几种:1. 使用包管理器解决冲突:大多数Linux发行版都提供了自己的包管理器,如apt...
    99+
    2023-09-22
    linux
  • Maven Pom 文件中的隐式依赖导致Jar冲突问题
    目录在maven项目中遇到这样一个场景解决了上述冲突的问题Maven 查看jar包依赖关系在maven项目中遇到这样一个场景 项目中的pom文件中,依赖了Spring-co...
    99+
    2024-04-02
  • maven依赖问题如何排查
    在排查Maven依赖问题时,可以尝试以下几个步骤:1. 检查pom.xml文件:首先检查项目的pom.xml文件,确保依赖项正确地被...
    99+
    2023-09-17
    maven
  • openSUSE中如何处理软件包依赖性问题
    在openSUSE中,处理软件包依赖性问题有几种常用的方法: 使用zypper命令:zypper是openSUSE中用于安装、删除...
    99+
    2024-04-02
  • Spring中怎么处理循环依赖问题
    Spring中怎么处理循环依赖问题,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。什么是循环依赖依赖指的是Bean与Bean之间的依赖关系,循环依赖指的是两个或者...
    99+
    2023-06-20
  • 如何理解Linux软件包依赖问题
    如何理解Linux软件包依赖问题,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。Linux软件包依赖关系让很多使用Linux的人感到很麻烦。在安装Linux系统时,不是选择安装所...
    99+
    2023-06-16
  • 如何使用replace属性来避免Composer的依赖冲突
    这篇文章将为大家详细讲解有关如何使用replace属性来避免Composer的依赖冲突,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Composer 文档提供了两个基本的示例。 我将尝试解释一下:列出被该...
    99+
    2023-06-09
  • springbean循环依赖问题如何解决
    Spring框架可以通过使用构造函数注入和setter方法注入两种方式来解决循环依赖问题。1. 构造函数注入:在循环依赖的类中,通过...
    99+
    2023-09-29
    springbean
  • maven循环依赖问题如何解决
    Maven循环依赖问题可以通过以下几种方式解决:1. 重新设计项目结构:循环依赖通常是由于项目结构设计不合理引起的。可以重新考虑项目...
    99+
    2023-09-17
    maven
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作