springcloud 添加 gateway 启动报错 Exception encountered during context initialization - cancelling refresh

springcloud 添加 gateway 启动报错

**********************************************************

Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.

**********************************************************


15.366 WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext:559  Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayConfigurationService' defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayConfigurationService' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.convert.ConversionService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}
15.369 INFO  o.a.c.core.StandardService    :173  Stopping service [Tomcat]
15.385 INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener:136  

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
15.521 ERROR o.s.boot.SpringApplication    :837  Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayConfigurationService' defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayConfigurationService' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.convert.ConversionService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:538)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at com.course.gateway.GatewayApplication.main(GatewayApplication.java:18)

原因 :

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

里面已经引入了

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

在pom文件或父项目的pom文件中找到重复引入,如下图:
在这里插入图片描述
此时启动报错
解决方式:删除多余的引入

<dependency>  
  <groupId>org.springframework.boot</groupId> 
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

删除后,启动成功
在这里插入图片描述
更深层次的原始是Gateway底层是webflux框架,在spring-cloud-starter-gateway中已经做了web初始化,springmvc再去初始化就会冲突,导致的报错

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
报错信息"Exception encountered during context initialization - cancelling refresh attempt"表示在上下文初始化期间遇到了异常并取消了刷新尝试。这个错误通常与Spring框架的bean初始化有关。它可能是由于配置文件的错误、依赖项的问题或bean定义的错误引起的。 根据引用和引用中的报错信息,这个错误可能与Spring框架中的sqlSessionFactory bean有关。在引用中提到了可能需要检查"com/wei/Mapper/UserMapper.xml"文件。 要解决这个错误,可以采取以下步骤: 1. 首先,检查是否正确配置了Spring框架的相关文件,包括配置文件和依赖项。 2. 确保所有的bean定义都正确无误,并且与实际的代码和配置相匹配。 3. 检查"com/wei/Mapper/UserMapper.xml"文件,确保它的路径和命名是正确的,并且没有语法错误或其他问题。 4. 如果有其他错误信息提供,可以进一步查看这些信息,以确定具体的问题所在。 5. 如果还无法解决问题,可以尝试搜索类似的错误信息和解决方案,或者向相关的开发社区寻求帮助。 总之,"Exception encountered during context initialization - cancelling refresh attempt"错误通常与Spring框架中的bean初始化相关,可能是由于配置文件错误、依赖项问题或bean定义错误引起的。通过检查配置文件、bean定义和错误信息,可以逐步解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Exception encountered during context initialization - cancelling refresh attempt](https://blog.csdn.net/weixin_62765017/article/details/127762302)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值