Fixing AOT compilation with multi binders

When default binder is provided and multiple binder types are
present on the classpath, then the binder requested as default
is not instantiated when compiling in AOT mode.

Resolves https://github.com/spring-cloud/spring-cloud-stream/issues/2584
This commit is contained in:
Soby Chacko
2022-12-12 18:09:48 -05:00
committed by Oleg Zhurakousky
parent 7a3f0f8197
commit 26be90d720

View File

@@ -167,6 +167,15 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
String configurationName = this.binderChildContextInitializers.keySet().iterator().next();
return this.getBinderInstance(configurationName);
}
else if (this.defaultBinder != null && this.binderChildContextInitializers.size() > 1) {
// Handling default binder when different binders are present on the classpath.
for (String binderName : this.binderChildContextInitializers.keySet()) {
if (binderName.equals(this.defaultBinder)) {
return this.getBinderInstance(binderName);
}
}
throw new IllegalStateException("Default binder provided, but can't determine which binder to initialize");
}
else {
throw new IllegalStateException("Can't determine which binder to use: " + name + "/" + this.binderChildContextInitializers.size());
}