我使用 spring-cloud-config 和 spring-cloud-bus 创建了一个简单的项目。由于某种原因,配置客户端两次调用配置服务器。第一次发生在创建引导程序的上下文时(预期的行为是什么),但第二次发生在创建绑定器的上下文时调用。
这是在课堂上完成的:
DefaultBinderFactory#getBinderInstance:
// If the environment is not customized and a main context is available, we
// will set the latter as parent.
// This ensures that the defaults and user-defined customizations (e.g. custom
// connection factory beans)
// are propagated to the binder context. If the environment is customized,
// then the binder context should
// not inherit any beans from the parent
boolean useApplicationContextAsParent = binderProperties.isEmpty() && this.context != null;
if (useApplicationContextAsParent) {
springApplicationBuilder.parent(this.context);
}
if (useApplicationContextAsParent || (environment != null && binderConfiguration.isInheritEnvironment())) {
if (environment != null) {
StandardEnvironment binderEnvironment = new StandardEnvironment();
binderEnvironment.merge(environment);
springApplicationBuilder.environment(binderEnvironment);
}
}
ConfigurableApplicationContext binderProducingContext = springApplicationBuilder
.run(args.toArray(new String[args.size()]));
当执行以下语句时:
ConfigurableApplicationContext binderProducingContext = springApplicationBuilder
.run(args.toArray(new String[args.size()]));
据我在代码中看到,绑定器的上下文与应用程序的上下文不同。看来再次调用配置服务器的原因是 spring-cloud-context 使用初始值设定项创建其上下文属性源引导配置由监听器加载Bootstrap应用监听器 .
所以,我的问题是:这是预期的行为吗?我假设配置客户端在启动时应该只向服务器发出一个请求。如果不正确,请问原因是什么?
我正在使用的版本包含在:
spring-cloud-dependencies,版本 Edgware.RELEASE
提前谢谢了!
是的;这是预期的; Spring Cloud Stream Binder被加载到它自己的Spring Boot应用程序中(它可以有不同的环境变量)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)