为什么Spring-cloud-starter-config会忽略bootstrap.properties? [英] Why bootstrap.properties is ignored by spring-cloud-starter-config?

查看:19
本文介绍了为什么Spring-cloud-starter-config会忽略bootstrap.properties?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是从config-service获取world-service的配置。

架构:

  1. config-service依赖spring-cloud-config-server位于localhost:8888
  2. world-service依赖spring-webspring-cloud-starter-config

我所做的:

  1. 我已经设置了配置服务器并向http://localhost:8888/hello-service/master发送了GET请求,配置服务器从the config-repo repository获取hello-service.properties。(如果您需要config-service的源代码,我会推送到this repository。)

我的预期结果: world-service使用端口8081。

我的实际结果: world-service使用端口8080。

bootstrap.properties

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

pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>world-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>world-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.0-M5</spring-cloud.version>
    </properties>

    <dependencies>
        <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>

    <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>

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

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>

</project>

推荐答案

在Spring Cloud 2020中,他们更改了引导的工作方式,您必须添加新的启动器:spring-cloud-starter-bootstrap

这篇关于为什么Spring-cloud-starter-config会忽略bootstrap.properties?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆