From 4c52eea730f82e04feda4329c5aa6a1619060e28 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 1 Apr 2021 17:23:42 +0200 Subject: [PATCH] Wrap synthesize EnableBinding in try/catch ignoring the error Appears to create problem in native images, but since we do not intend to support annotation-based programming model, we can just ignore this exception until we can remove this code all together. --- .../stream/config/BindingBeansRegistrar.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/BindingBeansRegistrar.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/BindingBeansRegistrar.java index 9ca769139..8d84213c5 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/BindingBeansRegistrar.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/BindingBeansRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,9 @@ package org.springframework.cloud.stream.config; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.binding.BindingBeanDefinitionRegistryUtils; @@ -34,22 +37,33 @@ import org.springframework.util.ClassUtils; */ public class BindingBeansRegistrar implements ImportBeanDefinitionRegistrar { + + private Log logger = LogFactory.getLog(this.getClass()); + @Override public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { AnnotationAttributes attrs = AnnotatedElementUtils.getMergedAnnotationAttributes( ClassUtils.resolveClassName(metadata.getClassName(), null), EnableBinding.class); - for (Class type : collectClasses(attrs, metadata.getClassName())) { - if (!registry.containsBeanDefinition(type.getName())) { - BindingBeanDefinitionRegistryUtils.registerBindingTargetBeanDefinitions( - type, type.getName(), registry); - BindingBeanDefinitionRegistryUtils - .registerBindingTargetsQualifiedBeanDefinitions(ClassUtils - .resolveClassName(metadata.getClassName(), null), type, - registry); + try { + for (Class type : collectClasses(attrs, metadata.getClassName())) { + if (!registry.containsBeanDefinition(type.getName())) { + BindingBeanDefinitionRegistryUtils.registerBindingTargetBeanDefinitions( + type, type.getName(), registry); + BindingBeanDefinitionRegistryUtils + .registerBindingTargetsQualifiedBeanDefinitions(ClassUtils + .resolveClassName(metadata.getClassName(), null), type, + registry); + } } } + catch (Exception e) { + logger.warn("Failed to proxy EnableBinding annotation. If you are using functional programming style, " + + "ignore this warning, otherwise, annotation-based programming model is not and will " + + "not be suppported in native images."); + // happens in native images, but we do not intend supporting annotation-based model for much longer + } } private Class[] collectClasses(AnnotationAttributes attrs, String className) {