在搭建分布式系统,建一个Zull微服务时,集成Zuul,在pom文件导入Zuul的依赖时,一直报错:

Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-starter-zuul:jar:1.3.1.RELEASE

网上逛了很久,没有找到能解决的办法,自己死磕了很久,最终完美解决。

问题:

在pom文件中导入Zull的依赖如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <!--在microservice-parent已经导入了spring clould-->
  <parent>
    <groupId>com.lzj.springcloud</groupId>
    <artifactId>microservice-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>microservice-zull</artifactId>

    <dependencies>
        <!-- zuul路由网关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
        <!-- 热部署插件 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

</project>

编译一直不通过,报Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-starter-zuul:jar:1.3.1的错误。

解决问题:

研究了一番,发现Zuul依赖于Eureaka,那么继续导入Eureka的依赖

    <dependencies>
        <!-- zuul路由网关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <!-- 热部署插件 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

发现编译还是不通过,依然报Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-starter-zuul:jar:1.3.1的错误。此时简直想吐,继续死磕。既然Zuul依赖Eureka,pom文件从上向下导入依赖时,那么当导入Zuul时,Eureka还没有导入进来,所以就一直报编译错误,那么把Eureka的依赖放在前面呢,如下:

    <dependencies>
        <!-- zuul路由网关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
        <!-- 热部署插件 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

发现问题解决,竟然编译通过了,推测导入Zuul时找不到Eureka的依赖导致的。当编译通过后,再把Zull的依赖放在Eureka的前面也不会报错了,因为maven已经装载了Eureka。
哈哈……

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐