Fix GatewayProxyInitAotProcessor for proper type

The `GatewayProxyInitializationAotProcessor` uses mistakenly a `ProxyFactoryBean` type
instead of an expected `GatewayProxyFactoryBean`.
Looks like we don't need to scan for interfaces since they are properly transformed
to the `AnnotationGatewayProxyFactoryBean` bean definition during AOT phase
This commit is contained in:
abilan
2022-11-16 11:51:11 -05:00
parent 2f1c202c20
commit cece9afbf2

View File

@@ -17,17 +17,14 @@
package org.springframework.integration.aot;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.aot.hint.ProxyHints;
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
import org.springframework.integration.gateway.RequestReplyExchanger;
@@ -45,22 +42,11 @@ class GatewayProxyInitializationAotProcessor implements BeanFactoryInitializatio
@Override
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
List<RegisteredBean> registeredBeans =
Stream<? extends Class<?>> gatewayProxyInterfaces =
Arrays.stream(beanFactory.getBeanDefinitionNames())
.map((beanName) -> RegisteredBean.of(beanFactory, beanName))
.toList();
Stream<Class<?>> gatewayProxyInterfaces =
Stream.concat(
registeredBeans.stream()
.filter(bean -> ProxyFactoryBean.class.isAssignableFrom(bean.getBeanClass()))
.map((bean) ->
bean.getBeanType().getGeneric(0).resolve(RequestReplyExchanger.class)),
registeredBeans.stream()
.map(RegisteredBean::getBeanClass)
.filter(beanClass ->
beanClass.isInterface() &&
AnnotatedElementUtils.hasAnnotation(beanClass, MessagingGateway.class)));
.filter((bean) -> GatewayProxyFactoryBean.class.isAssignableFrom(bean.getBeanClass()))
.flatMap((bean) -> Stream.ofNullable(bean.getBeanType().getGeneric(0).resolve()));
return (generationContext, beanFactoryInitializationCode) -> {
ProxyHints proxyHints = generationContext.getRuntimeHints().proxies();