-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于SpringCloud的bootstrap阶段PropertySources的建议 #3610
Comments
主要的问题是担心 spring.application.name/server.port 这些值被远端配置覆盖掉? |
@nobodyiam 是这个意思。 我觉得大多数场景用户应该不会有这种自由意图,在项目立项之初, 结合SpringCloud配置的做法,我猜测它也希望在bootstrap阶段,内置组件初始化注入所需的配置不被扩展配置影响。在重启(故障或手动)动作之后,应用程序 虽然可以通过 非Spring项目或者SpringBoot项目不存在这个问题,但是在SpringCloud项目我比较在意这种不可控因素,还是挺希望能与SpringCloud自身的扩展配置机制有一致的行为。不知道是否考虑 |
Spring Boot 项目为啥不存在这个问题?spring.application.name/server.port 这些值也是可以配置的 |
抱歉,描述不准确。应当是“不存在这个争议”,spring-boot默认只有一个environment,对PropertySource的扩展各家自由度较高(我司 而spring-cloud多了一个bootstrap引导阶段,
上述我理解为spring-cloud希望只从 我司 描述不正确的地方请指正。 |
感谢详细的说明,单独抽离一个项目 |
是的,是这个效果。
不好意思之前也没细看2020版本的变化。查了一下,从2020开始SpringCloud默认不再使用bootstrapContext引导启动了,加载configserver只需要这样: |
看了一下相关的源码,单独建一个 |
你的特性请求和某个问题有关吗?请描述
bootstrap.yml/properties
文件中(例如spring.application.name
、远程配置地址/开关等),而将远程配置PropertySource放置在子上下文环境中。我认同这种机制能很好的隔离用户和环境配置,用户在远程的配置不会影响到某些预设配置(如服务ID、注册中心地址等)。spring.application.name
等配置值仍会优先从Apollo远程配置中获取,极易因用户的不当配置引发预期之外的问题,如调用链路中断(spring.application.name
常被用于各种组件的唯一标识,如eureka服务的appId;这种是应当在项目建立时就固定的约定)。清晰简洁地描述一下你希望的解决方案
ApolloPropertySources
或者使用推荐的扩展方式引入ApolloPropertySources
(在spring.factories
中扩展org.springframework.cloud.bootstrap.BootstrapConfiguration
)。清晰简洁地描述一下这个特性的备选方案
EnvironmentPostProcessor
中通过提前占位的方式阻止bootstrap阶段的ApolloBootstrapPropertySources
添加。如图所示:其它背景
The text was updated successfully, but these errors were encountered: