正如我在新版本的spring-cloud-stream 2.1.0(spring-cloud greenwich)中看到的那样。在 org.springframework.cloud.stream.binder.DefaultBinderFactory
类中public class DefaultBinderFactory implements BinderFactory, DisposableBean, ApplicationContextAware {
private final Map<String, BinderConfiguration> binderConfigurations;
(...)
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public synchronized <T> Binder<T, ?, ?> getBinder(String name, Class<? extends T> bindingTargetType) {
String binderName = StringUtils.hasText(name) ? name : this.defaultBinder;
Map<String, Binder> binders = this.context == null ? Collections.emptyMap() : this.context.getBeansOfType(Binder.class);
Binder<T, ConsumerProperties, ProducerProperties> binder;
if (StringUtils.hasText(binderName) && binders.containsKey(binderName)) {
binder = (Binder<T, ConsumerProperties, ProducerProperties>) this.context.getBean(binderName);
}
else if (binders.size() == 1) {
binder = binders.values().iterator().next();
}
else if (binders.size() > 1) {
throw new IllegalStateException("Multiple binders are available, however neither default nor "
+ "per-destination binder name is provided. Available binders are " + binders.keySet());
}
else {
/*
* This is the fall back to the old bootstrap that relies on spring.binders.
*/
binder = this.doGetBinder(binderName, bindingTargetType);
}
return binder;
}
似乎新方法是从应用程序上下文中加载活页夹,而不是创建新的活页夹。除了回退到旧的引导程序之外,我想这是用于使用尚未更改方法的活页夹。
看到代码,出现了两个问题:
此外,我在文档中看不清:
一方面,在8.3.1中说:
8.3.1类路径检测 默认情况下,Spring Cloud Stream 依靠Spring Boot的自动配置来配置绑定过程。
在8.4点时:
8.4类路径上的多个绑定器(...)每个绑定器配置都包含一个META-INF / spring.binders
这是否意味着在没有使用spring.binders的旧方法的情况下配置多个活页夹是不可能的?有我不知道的配置方法吗?