我有一个配置文件存储在git repositoryhttps://github.com/katya-dovgalets/config.git中
消息.properties
其中包含一行
message service.sendername=卡蒂娅
我有一个简单的项目,从上面的存储库中获取数据。
我有
demoapplication.java软件
@SpringBootApplication
@EnableConfigServer
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
应用程序.属性
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
当我通过http://localhost:8881/message.properties链接时
最佳答案
您必须将客户机属性添加到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=*
在服务器端:
server.port=8881
spring.cloud.config.server.git.uri=https://github.com/katya-dovgalets/config.git
现在您可以访问http://localhost:8881/message/default查看配置的属性。
然后,您需要
application.properties
和curl
来反映这些变化。
关于java - 无法使用Spring Cloud配置服务器从配置文件中获取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58130940/