java - 为什么 bootstrap.properties 被 spring-cloud-starter-config 忽略?

标签 java spring spring-boot spring-cloud spring-cloud-config

我的目标是获取 world-service 的配置来自 config-service .
架构:

  • config-service有依赖性 spring-cloud-config-serverlocalhost:8888
  • world-service依赖 spring-webspring-cloud-starter-config .

  • 我做了什么:
  • 我已经设置了配置服务器并向 http://localhost:8888/hello-service/master 发送了一个 GET 请求并且配置服务器得到 hello-service.properties来自 the config-repo repository . (如果你需要 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 中,他们对 bootstrap 的工作方式进行了更改,您必须包含一个新的启动程序:spring-cloud-starter-bootstrap .

    关于java - 为什么 bootstrap.properties 被 spring-cloud-starter-config 忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65063402/

    相关文章:

    java - 如何从 NETTY 4 中的 post 请求中获取文件数据?

    java - 配置 Jersey 时,Spring Boot HandlerInterceptor 没有触发?

    java - 将 spring.config.location 设置为相对路径

    AngularJs View 与 Spring : Not showing

    java - 使用 Spring Security 将 Web 资源列入白名单

    spring-boot - 失败 : (ID: 838926df) did not find any jar files with a Main-Class manifest entry

    java - 如何正确打包maven多模块?

    java - Eclipse 和 Java : Is there an event monitoring feature?

    java - 为什么Spring中的作用域会影响Spring中类的加载

    java - 具有独立 hbase 的 spring hbase 示例