今天在建立eureka微服务过程中,pom文件中一直报“Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-st”的错误,并且在启动类上添加注解@EnableEurekaServer,显示不存在该注解。原因是没有正确导入eureka需要的依赖。

eureka微服务中pom文件如下

<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>
    <parent>
        <groupId>com.lzj.springcloud</groupId>
        <artifactId>microservice-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>microservice-eurake1</artifactId>

    <dependencies>
        <!--eureka-server服务端 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</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>

在依赖的父工程microservice-parent工程中已经导入了SpringCloud版本,所以在eureka微服务中的pom文件中就不需要再导入SpringCloud了,父工程导入的SpringCloud版本为

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

但是按上面的进行配置完后,eureka的pom文件上一直提示“Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-st”的错误,并且在启动类上也没有@EnableEurekaServer注解。猜测应该是SpringCloud版本的原因,导致的eureka的依赖包的方式不正确,把eureka微服务中的pom文件改成如下就可以了,问题就完美的解决了。

<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>
    <parent>
        <groupId>com.lzj.springcloud</groupId>
        <artifactId>microservice-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>microservice-eurake1</artifactId>

    <dependencies>
        <!--eureka-server服务端 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-eureka-server</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>
Logo

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

更多推荐