Spring Boot配置客户端无法解析配置服务器

问题描述 投票:0回答:1

配置客户端无法解析配置属性,并且无法连接到配置服务器。这是我的服务application.properties文件:

spring.application.name = idmanager-service
spring.cloud.config.uri = http://localhost:8888

server.port=8081

#enable actuator endpoints
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
info.app.name=Id management Application
info.app.description=managing citizens identities
info.app.version=0.1.0

pom.xml中的依赖项:

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

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

        <!-- Lmobok Dependency-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.2</version>
            <scope>provided</scope>
        </dependency>
        <!-- / Lmobok Dependency-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <!--<version>RELEASE</version>-->
            <scope>compile</scope>
        </dependency>

        <!-- Eureka discovery client-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-commons</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>

        <!-- Config client-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <!-- Actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

    </dependencies>

配置服务器和发现服务器已成功启动,并且其他服务已成功注册。

这是配置服务器的application.properties文件:

server.port=8888
spring.cloud.config.server.git.uri=file:./src/main/resources/myConfig

myConfig文件夹中的application.properties文件:

global=xxxxx

其他服务已成功注册并获取配置服务器:c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888

spring-boot spring-cloud-config spring-cloud-config-server
1个回答
0
投票

我通过修复如下所示的Spring云版本解决了此问题:<spring-cloud.version>Hoxton.SR3</spring-cloud.version>

然后我使用依赖项管理指定了Spring Cloud依赖项版本:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>
© www.soinside.com 2019 - 2024. All rights reserved.