java - 为什么 spring-cloud-starter-config 忽略 bootstrap.properties?
问题描述
我的目标是world-service
从config-service
.
架构:
config-service
依赖spring-cloud-config-server
于localhost:8888
world-service
依赖于spring-web
andspring-cloud-starter-config
。
我做了什么:
- 我已经设置了配置服务器并向其发送 GET 请求,
http://localhost:8888/hello-service/master
并且配置服务器hello-service.properties
从config-repo 存储库中获取。(如果您需要config-service
的源代码,我会将其推送到此存储库。)
我的预期结果:world-service
使用端口 8081。
我的实际结果:world-service
使用端口 8080。
引导程序属性
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
.
推荐阅读
- r - R中不同维度数组的总和
- r - 如何在 csv 文件上运行多个函数,然后将结果写入 r 中的新 csv 文件?
- c++ - 虚幻宏蓝图到 C++
- numpy - NUMPY:是否有更易读的方式来索引 numpy 数组?
- reactjs - 如何在 React Native 中的抽屉导航组件中嵌套堆栈导航
- python - Selenium Pytest GitLab CI - pytest 问题
- php - 致命错误:未捕获的类型错误:count():参数 #1 ($var) 必须是 Countable|array 类型,在
- c# - Entity Framework 6 不能选择所有列,只能选择一个子集
- mocking - SoapUI:一次运行多个具有相同端口和路径的 Soap Mock 服务
- android - Android Lint 消息:更新到 Fragment 1.3.0 以在分析/检查代码中使用 ActivityResult API 错误