use of org.springframework.cloud.stream.binder.DefaultBinderTypeRegistry in project spring-cloud-stream by spring-cloud.
the class BinderFactoryAutoConfiguration method binderTypeRegistry.
@Bean
public BinderTypeRegistry binderTypeRegistry(ConfigurableApplicationContext configurableApplicationContext) {
Map<String, BinderType> binderTypes = new HashMap<>();
ClassLoader classLoader = configurableApplicationContext.getClassLoader();
try {
Enumeration<URL> resources = classLoader.getResources("META-INF/spring.binders");
// see if test binder is available on the classpath and if so add it to the binderTypes
try {
BinderType bt = new BinderType("integration", new Class[] { classLoader.loadClass("org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration") });
binderTypes.put("integration", bt);
} catch (Exception e) {
// ignore. means test binder is not available
}
if (binderTypes.isEmpty() && !Boolean.valueOf(this.selfContained) && (resources == null || !resources.hasMoreElements())) {
this.logger.debug("Failed to locate 'META-INF/spring.binders' resources on the classpath." + " Assuming standard boot 'META-INF/spring.factories' configuration is used");
} else {
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
UrlResource resource = new UrlResource(url);
for (BinderType binderType : parseBinderConfigurations(classLoader, resource)) {
binderTypes.put(binderType.getDefaultName(), binderType);
}
}
}
} catch (IOException | ClassNotFoundException e) {
throw new BeanCreationException("Cannot create binder factory:", e);
}
return new DefaultBinderTypeRegistry(binderTypes);
}
use of org.springframework.cloud.stream.binder.DefaultBinderTypeRegistry in project spring-cloud-stream by spring-cloud.
the class BinderFactoryConfiguration method binderTypeRegistry.
@Bean
@ConditionalOnMissingBean(BinderTypeRegistry.class)
public BinderTypeRegistry binderTypeRegistry(ConfigurableApplicationContext configurableApplicationContext) {
Map<String, BinderType> binderTypes = new HashMap<>();
ClassLoader classLoader = configurableApplicationContext.getClassLoader();
// the above can never be null since it will default to ClassUtils.getDefaultClassLoader(..)
try {
Enumeration<URL> resources = classLoader.getResources("META-INF/spring.binders");
if (!Boolean.valueOf(this.selfContained) && (resources == null || !resources.hasMoreElements())) {
throw new BeanCreationException("Cannot create binder factory, no `META-INF/spring.binders` " + "resources found on the classpath");
}
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
UrlResource resource = new UrlResource(url);
for (BinderType binderType : parseBinderConfigurations(classLoader, resource)) {
binderTypes.put(binderType.getDefaultName(), binderType);
}
}
} catch (IOException | ClassNotFoundException e) {
throw new BeanCreationException("Cannot create binder factory:", e);
}
return new DefaultBinderTypeRegistry(binderTypes);
}
use of org.springframework.cloud.stream.binder.DefaultBinderTypeRegistry in project spring-cloud-stream by spring-cloud.
the class TestChannelBinderConfiguration method binderTypeRegistry.
@Bean
public BinderTypeRegistry binderTypeRegistry() {
BinderType binderType = new BinderType(NAME, new Class[] { TestChannelBinderConfiguration.class });
BinderTypeRegistry btr = new DefaultBinderTypeRegistry(Collections.singletonMap(NAME, binderType));
return btr;
}
Aggregations