我有一个配置文件存储在git存储库https://github.com/katya-dovgalets/config.git中,其中
message.properties
其中包含一行
message-service.senderName = Katya
我有一个简单的项目,该项目从上述存储库中获取数据。 我有
DemoApplication.java
@SpringBootApplication
@EnableConfigServer
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
application.properties
server.port=8881
spring.cloud.config.server.git.uri=https://github.com/katya-dovgalets/config.git
和
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.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</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>
</project>
我希望看到类似
的内容发件人名称:Katya
答案 0 :(得分:1)
您将必须将客户端属性添加到bootstrap.properties
,而不是application.properties
。这是您需要添加到bootstrap.properties
中的内容:
server.port=8888
spring.application.name=message
spring.cloud.config.uri=http://localhost:8881
management.endpoints.web.exposure.include=*
在服务器端application.properties
:
server.port=8881
spring.cloud.config.server.git.uri=https://github.com/katya-dovgalets/config.git
现在,您可以访问http://localhost:8881/message/default来查看配置的属性。
然后,您需要将curl
的{{1}}与POST
一起使用以反映这些更改。