欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

關(guān)于Springboot+gateway整合依賴并處理依賴沖突問題

 更新時間:2022年01月06日 16:54:56   作者:怒吼的蘿卜  
這篇文章主要介紹了Springboot+gateway整合依賴并處理依賴沖突問題,給大家提到了spring boot版本和spring cloud版本,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

正文

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網(wǎng)關(guān)轉(zhuǎn)發(fā)請求時可能發(fā)生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: 8700
spring:
  application:
    name: sca-gateway
  cloud:
    gateway:
      routes: #配置網(wǎng)關(guān)路由規(guī)則
        - id: route01  #路由id,自己指定一個唯一值即可
          uri: http://localhost:8081/ #網(wǎng)關(guān)幫我們轉(zhuǎn)發(fā)的url
          predicates: ###斷言(謂此):匹配請求規(guī)則
            - Path=/nacos/provider/echo/**  #請求路徑定義,此路徑對應(yīng)uri中的資源
          filters: ##網(wǎng)關(guān)過濾器,用于對謂詞中的內(nèi)容進行判斷分析以及處理
            - StripPrefix=1 #轉(zhuǎn)發(fā)之前去掉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依賴發(fā)生沖突,因為gateway依賴包內(nèi)置spring-boot-starter-webflux依賴,與web包內(nèi)的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>

到此這篇關(guān)于Springboot+gateway整合依賴并處理依賴沖突問題的文章就介紹到這了,更多相關(guān)Springboot gateway依賴沖突內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • SpringBoot接口請求入?yún)⒑统鰠⒃鰪姷奈宸N方法

    SpringBoot接口請求入?yún)⒑统鰠⒃鰪姷奈宸N方法

    這篇文章主要介紹了SpringBoot接口請求入?yún)⒑统鰠⒃鰪姷奈宸N方法,使用`@JsonSerialize`和`@JsonDeserialize`注解,全局配置Jackson的`ObjectMapper`,使用`@ControllerAdvice`配合`@InitBinder`,自定義HttpMessageConverter和使用AOP進行切面編程,需要的朋友可以參考下
    2024-07-07
  • idea打開和讀取*properties文件亂碼的解決

    idea打開和讀取*properties文件亂碼的解決

    本文主要介紹了idea打開和讀取*properties文件亂碼的解決,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-09-09
  • Spring注解之@Lazy注解使用解析

    Spring注解之@Lazy注解使用解析

    這篇文章主要介紹了Spring注解之@Lazy注解使用解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-09-09
  • 解析如何用兩個棧來實現(xiàn)隊列的方法

    解析如何用兩個棧來實現(xiàn)隊列的方法

    本篇文章是對如何用兩個棧實現(xiàn)隊列的方法進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • 關(guān)于弱引用WeakReference所引用的對象的回收規(guī)則

    關(guān)于弱引用WeakReference所引用的對象的回收規(guī)則

    這篇文章主要介紹了關(guān)于弱引用WeakReference所引用的對象的回收規(guī)則,如果一個弱引用實例的成員變量referent引用了一個對象obj,那么就稱這個弱引用實例對obj的引用是弱引用,被一個弱引用實例引用的對象,稱為弱引用對象,需要的朋友可以參考下
    2023-09-09
  • 深入理解 Java、Kotlin、Go 的線程和協(xié)程

    深入理解 Java、Kotlin、Go 的線程和協(xié)程

    這篇文章主要介紹了深入理解 Java、Kotlin、Go 的線程和協(xié)程,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • Java使用JSONObject操作json實例解析

    Java使用JSONObject操作json實例解析

    這篇文章主要介紹了Java使用JSONObject操作json,結(jié)合實例形式較為詳細的分析了Java使用JSONObject解析json數(shù)據(jù)相關(guān)原理、使用技巧與操作注意事項,需要的朋友可以參考下
    2020-04-04
  • springboot斷點上傳、續(xù)傳、秒傳實現(xiàn)方式

    springboot斷點上傳、續(xù)傳、秒傳實現(xiàn)方式

    這篇文章主要介紹了springboot斷點上傳、續(xù)傳、秒傳實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • SpringBoot解決數(shù)據(jù)庫時間和返回時間格式不一致的問題

    SpringBoot解決數(shù)據(jù)庫時間和返回時間格式不一致的問題

    這篇文章主要介紹了SpringBoot解決數(shù)據(jù)庫時間和返回時間格式不一致的問題,文章通過代碼示例和圖文結(jié)合的方式講解的非常詳細,對大家的學(xué)習(xí)和工作有一定的幫助,需要的朋友可以參考下
    2024-03-03
  • idea項目debug模式無法啟動的解決

    idea項目debug模式無法啟動的解決

    這篇文章主要介紹了idea項目debug模式無法啟動的解決,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02

最新評論