spring-boot - 多个微服务的通用应用程序属性文件

标签 spring-boot microservices netflix-eureka netflix-zuul spring-cloud-config

我想为多个微服务使用一个通用的应用程序属性文件,这些微服务将具有一些通用配置,如数据库源配置等。我已经将配置服务器与 Eureka 服务器和 zull 代理一起使用。

问题:

使用configServer时我们需要提供spring.application.name = 'xyz' 进而找到此微服务配置的 xyz.properties。

同理我们在zuul proxy注册服务时也需要相同的应用名来配置服务路径为zuul.routes.xyz.path =/iii/*。

现在我希望多个服务共享相同的属性文件 (xyz.properties),但还需要注册 zuul 路由,因此我必须为每个服务提供不同的名称。如果我为每个服务提供不同的名称,它们将无法找到相同的属性文件。

我是 spring boot 微服务的新手。

最佳答案

spring.config.client.name 支持以逗号分隔的多个名称来加载配置属性。

在这种情况下,将公共(public)属性存储在 common.yml 中,将 xyz 属性存储在 xyz.yml 中。最后提一下spring.cloud.config.name: xyz,common

spring:
  cloud:
    config:
      uri: http://localhost:8888
      name: xyz,common

输出:

Fetching config from server at : http://localhost:8888
Located environment: name=xyz,common, profiles=[default], label=null, version=91edcf96c6a88707bf39014a16ad5d301d6b4575, state=null
Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://github.com/BarathArivazhagan/config-server-repository/common.yml'}, MapPropertySource {name='https://github.com/BarathArivazhagan/config-server-repository/xyz.yml'}]}

关于spring-boot - 多个微服务的通用应用程序属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54502883/

相关文章:

spring-boot - 在 Spring Boot 微服务中为多个 Controller 配置 Swagger

java - Spring Boot Rest 在注册时设置用户默认配置文件图像

postgresql - Gradle项目中如何连接PostgreSQL

netflix-eureka - Spring boot eureka - 删除死服务

spring-boot - 如何将服务生成的 nodePort 注入(inject)到部署中?

java - Spring Security - 发布到不安全的页面会导致 403

java - Spring Boot中无法建立一对一关系,@JoinColumns(列不存在)

microservices - 词汇题: am I doing a micro-service or just SOA?

spring-boot - 如何在微服务架构中实现基于角色的安全

spring-boot - 我在使用 springboot 3.0.0 时遇到问题,它无法识别我的 Eureka 服务器和客户端