Spring Cloud Bootstrap.yml 覆盖 Application.yml 参数配置指南
要覆盖 application.yml 中的参数,可以在 Spring Cloud 的 bootstrap.yml 中进行配置。以下是配置的步骤:
- 创建一个名为 'bootstrap.yml' 的文件,放在 src/main/resources 目录下。
- 在 'bootstrap.yml' 中添加需要覆盖的参数,例如:
spring:
application:
name: 'my-application'
cloud:
config:
uri: 'http://config-server:8888'
在上面的示例中,覆盖了 application.yml 中的 'spring.application.name' 和 'spring.cloud.config.uri' 参数。
- 确保 'bootstrap.yml' 中的参数会在应用程序启动时加载。可以通过以下方式来实现:
- 确保应用程序的启动类上有 '@EnableConfigServer' 或 '@EnableDiscoveryClient' 注解。
- 在应用程序的启动类上添加 '@EnableAutoConfiguration' 注解。
这样,当应用程序启动时,它会首先加载 'bootstrap.yml' 中的参数,然后再加载 application.yml 中的参数。如果有参数冲突,则以 'bootstrap.yml' 中的为准。
原文地址: http://www.cveoy.top/t/topic/M2W 著作权归作者所有。请勿转载和采集!