我完全陷入了配置客户端无法从配置文件服务器获取配置的问题。我正在尝试使用 spring.config.import 通过“新方式”来做到这一点,但看起来我错过了一些东西。
我将属性文件存储在私有 github 存储库中。这是我的配置文件服务器:application.properties:
spring.application.name=config-server
server.port=8888
spring.cloud.config.server.git.uri=https://github.com/Pavello/simple-microservices-app-config-files-repo
spring.cloud.config.server.git.username=//My username
spring.cloud.config.server.git.password=//Here I am using my private token
spring.cloud.config.server.git.default-label=master
management.endpoints.web.exposure.include=busrefresh
spring.rabbitmq.host=localhost
spring.rabbitmq.user=guest
spring.rabbitmq.password=guest
spring.rabbitmq.port=5672
Run Code Online (Sandbox Code Playgroud)
pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的客户端应用程序如下所示:application.properties:
server.port=${PORT:0}
spring.application.name=user-service
eureka.client.serviceUrl.defaultZone=http://localhost:8010/eureka
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}}
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true
spring.config.import=optional:configserver:http://localhost:8888
management.endpoints.web.exposure.include=*
Run Code Online (Sandbox Code Playgroud)
pom.xml 依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId> …Run Code Online (Sandbox Code Playgroud)