springboot注册到consul中报错:Spring MVC found on classpath, which is incompatible with Spring Cloud

2023-11-19

今天在做springboot整合成springCloud并注册到consul中时,发现若注册到consule中成功 则不能启动swagger,且不能提供任何API服务,要是能提供API服务则不能注册到consule中,并报错“

Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. "+

     "Please remove spring-boot-starter-web dependency

分析了一下,发现在如下代码中会报这个log信息

@Configuration

@AutoConfigureBefore(GatewayAutoConfiguration.class)

public class GatewayClassPathWarningAutoConfiguration {

 private static final Log log = LogFactory.getLog(GatewayClassPathWarningAutoConfiguration.class);

 private static final String BORDER = "\n\n**********************************************************\n\n";

 @Configuration

 @ConditionalOnClass(name = "org.springframework.web.servlet.DispatcherServlet")

 protected static class SpringMvcFoundOnClasspathConfiguration {

  public SpringMvcFoundOnClasspathConfiguration() {

   log.warn(BORDER+"Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. "+

     "Please remove spring-boot-starter-web dependency."+BORDER);

  }

 }

 @Configuration

 @ConditionalOnMissingClass("org.springframework.web.reactive.DispatcherHandler")

 protected static class WebfluxMissingFromClasspathConfiguration {

  public WebfluxMissingFromClasspathConfiguration() {

   log.warn(BORDER+"Spring Webflux is missing from the classpath, which is required for Spring Cloud Gateway at this time. "+

     "Please add spring-boot-starter-webflux dependency."+BORDER);

  }

 }

}

最终,我们分析是swagger启动时所要的jar包和springCloud有所冲突,修改我们的POM文件如下,主要是版本的问题:

   发现consul 1.2版本需要和SpringCloud的Finchley版本才能整合

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
 
 
 
 
 
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

springboot注册到consul中报错:Spring MVC found on classpath, which is incompatible with Spring Cloud 的相关文章

随机推荐