【问题标题】:Spring boot and spring cloud config client errorSpring Boot 和 Spring Cloud 配置客户端错误
【发布时间】:2016-04-15 18:19:39
【问题描述】:

我正在尝试使用 spring cloud config 客户端配置和运行 spring boot 应用程序。我已成功运行配置服务器,但客户端在加载应用程序上下文时出错。

在搜索时,我得到了指向版本/依赖冲突等的指针,并尝试使用不同的版本。任何帮助将不胜感激。

错误sn-p:

Caused by: java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

以下是示例 pom。

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>com.example</groupId>
    <artifactId>lab-3-client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>lab-3-client</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>com.example.Lab3ClientApplication</start-class>

        <java.version>1.8</java.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-parent</artifactId>
                <version>Angel.SR4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

【问题讨论】:

  • @asgs 谢谢,但我已经阅读并尝试了这些选项。我尝试将 spring.version 指定为 4.2.1 ;试图做 mvn -U clean install ;尝试明确指定较低版本的 cloud-starter-config 并尝试更改我的依赖项的顺序等。但还没有运气:-(
  • 好的,提到的缺失类来自spring-context artifact。

标签: java spring maven spring-boot spring-cloud


【解决方案1】:

Angel 发布系列基于 Spring Boot 1.2.x,在某些方面与 Spring Boot 1.3.x 不兼容。所以,我会把spring boot的版本改成1.2.7.RELEASE

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.7.RELEASE</version>
</parent>

【讨论】:

  • 谢谢。如果我使用版本 1.2.7.RELEASE 它正在加载并运行。但是,它似乎不适用于云配置服务器,即没有从已经运行的服务器中检索配置。服务器正在使用最新的 spring boot 运行。如果有任何变化会继续更新...
  • 默认情况下,spring cloud config客户端会寻找一个运行在8888端口localhost的配置服务器。
  • 其实好像还有别的问题。 /metrics api 正在返回 status=404 。配置服务器也可以正常工作,如果我使用客户端 id 调用配置服务器 api,它会返回正确的配置值。
  • 我在 8001 运行配置服务器,但在客户端的 bootstrap.properties 中指定了以下内容:spring.cloud.config.uri=localhost:8001 .... 虽然它似乎是一些/metrics 返回 404 的其他问题
【解决方案2】:

尝试将以下内容添加到您的&lt;dependencyManagement&gt; &lt;dependencies&gt;

    <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-parent</artifactId>
            <version>Angel.SR4</version>
            <type>pom</type>
            <scope>import</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>1.3.1.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency> 

【讨论】:

    猜你喜欢
    • 2017-01-02
    • 2020-05-02
    • 1970-01-01
    • 2019-02-15
    • 2017-09-12
    • 2015-06-20
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    相关资源
    最近更新 更多