Skip to content

Commit 0d8e286

Browse files
authored
GH-3903: Improve AOT for gateway proxy beans (#3904)
* GH-3903: Improve AOT for gateway proxy beans Fixes #3903 * Fix `MessagingGatewayRegistrar` to set a `targetType` on the bean definition instead of `FactoryBean.OBJECT_TYPE_ATTRIBUTE` * Rework `GatewayProxyBeanRegistrationAotProcessor` to the `GatewayProxyInitializationAotProcessor implements BeanFactoryInitializationAotProcessor` to avoid custom code generation * Remove tests which rely on the `FactoryBean.OBJECT_TYPE_ATTRIBUTE` * * Add `setBeanClass(GatewayProxyFactoryBean.class)` to satisfy Spring container expectations * * Rework `GatewayProxyInitializationAotProcessor` to deal with generics we are exposing now on the `ProxyFactoryBean`
1 parent dc56c09 commit 0d8e286

File tree

3 files changed

+59
-76
lines changed

3 files changed

+59
-76
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aot/GatewayProxyBeanRegistrationAotProcessor.java

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.aot;
18+
19+
import java.util.Arrays;
20+
import java.util.List;
21+
22+
import org.springframework.aop.framework.AopProxyUtils;
23+
import org.springframework.aop.framework.ProxyFactoryBean;
24+
import org.springframework.aot.hint.ProxyHints;
25+
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
26+
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
27+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
28+
import org.springframework.beans.factory.support.RegisteredBean;
29+
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
30+
import org.springframework.integration.gateway.RequestReplyExchanger;
31+
32+
/**
33+
* A {@link BeanFactoryInitializationAotProcessor} for registering proxy interfaces
34+
* of the {@link GatewayProxyFactoryBean} beans.
35+
*
36+
* @author Artem Bilan
37+
*
38+
* @since 6.0
39+
*/
40+
class GatewayProxyInitializationAotProcessor implements BeanFactoryInitializationAotProcessor {
41+
42+
@Override
43+
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
44+
List<? extends Class<?>> gatewayProxyInterfaces =
45+
Arrays.stream(beanFactory.getBeanDefinitionNames())
46+
.map((beanName) -> RegisteredBean.of(beanFactory, beanName))
47+
.filter((bean) -> ProxyFactoryBean.class.isAssignableFrom(bean.getBeanClass()))
48+
.map((bean) -> bean.getBeanType().getGeneric(0).resolve(RequestReplyExchanger.class))
49+
.toList();
50+
51+
return (generationContext, beanFactoryInitializationCode) -> {
52+
ProxyHints proxyHints = generationContext.getRuntimeHints().proxies();
53+
gatewayProxyInterfaces.forEach((gatewayInterface) ->
54+
proxyHints.registerJdkProxy(AopProxyUtils.completeJdkProxyInterfaces(gatewayInterface)));
55+
};
56+
}
57+
58+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar=org.springframework.integration.aot.CoreRuntimeHints
2-
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=org.springframework.integration.aot.GatewayProxyBeanRegistrationAotProcessor
2+
org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=org.springframework.integration.aot.GatewayProxyInitializationAotProcessor
33
org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter=org.springframework.integration.aot.IntegrationBeanRegistrationExcludeFilter

0 commit comments

Comments
 (0)