Skip to content

Commit 2ecc33e

Browse files
artembilangaryrussell
authored andcommitted
Improve AOT for some infrastructure
* Add more proxy hints for interfaces we use in the framework code * Implement `BeanRegistrationExcludeFilter` to exlude `BeanFactoryPostProcessor` beans * Remove `AotDetector.useGeneratedArtifacts()` from those `BFPP`s
1 parent 15e89c3 commit 2ecc33e

File tree

5 files changed

+81
-32
lines changed

5 files changed

+81
-32
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import org.springframework.beans.factory.config.BeanExpressionContext;
3939
import org.springframework.context.SmartLifecycle;
4040
import org.springframework.core.DecoratingProxy;
41+
import org.springframework.integration.aggregator.MessageGroupProcessor;
4142
import org.springframework.integration.context.IntegrationContextUtils;
4243
import org.springframework.integration.core.GenericSelector;
44+
import org.springframework.integration.core.MessageSource;
4345
import org.springframework.integration.dsl.IntegrationFlow;
4446
import org.springframework.integration.gateway.MethodArgsHolder;
4547
import org.springframework.integration.gateway.RequestReplyExchanger;
@@ -56,7 +58,9 @@
5658
import org.springframework.integration.support.MutableMessage;
5759
import org.springframework.integration.support.MutableMessageHeaders;
5860
import org.springframework.integration.transformer.GenericTransformer;
61+
import org.springframework.messaging.MessageHandler;
5962
import org.springframework.messaging.MessageHeaders;
63+
import org.springframework.messaging.PollableChannel;
6064
import org.springframework.messaging.support.ErrorMessage;
6165
import org.springframework.messaging.support.GenericMessage;
6266

@@ -134,6 +138,10 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
134138

135139
ProxyHints proxyHints = hints.proxies();
136140

141+
registerSpringJdkProxy(proxyHints, PollableChannel.class);
142+
registerSpringJdkProxy(proxyHints, MessageSource.class);
143+
registerSpringJdkProxy(proxyHints, MessageHandler.class);
144+
registerSpringJdkProxy(proxyHints, MessageGroupProcessor.class);
137145
registerSpringJdkProxy(proxyHints, RequestReplyExchanger.class);
138146
registerSpringJdkProxy(proxyHints, AbstractReplyProducingMessageHandler.RequestHandler.class);
139147
registerSpringJdkProxy(proxyHints, IntegrationFlow.class, SmartLifecycle.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
21+
import org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter;
22+
import org.springframework.beans.factory.support.RegisteredBean;
23+
import org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor;
24+
import org.springframework.integration.config.IntegrationConfigurationBeanFactoryPostProcessor;
25+
26+
/**
27+
* The {@link BeanRegistrationExcludeFilter} to exclude beans not need at runtime anymore.
28+
* Usually {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor} beans
29+
* are excluded since they have contributed their bean definitions code generated during AOT
30+
* build phase.
31+
*
32+
* @author Artem Bilan
33+
*
34+
* @since 6.0
35+
*/
36+
class IntegrationBeanRegistrationExcludeFilter implements BeanRegistrationExcludeFilter {
37+
38+
@Override
39+
public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) {
40+
Class<?> beanClass = registeredBean.getBeanClass();
41+
return Arrays.asList(DefaultConfiguringBeanFactoryPostProcessor.class,
42+
IntegrationConfigurationBeanFactoryPostProcessor.class)
43+
.contains(beanClass);
44+
}
45+
46+
}

spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.Set;
2424
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
2525

26-
import org.springframework.aot.AotDetector;
2726
import org.springframework.beans.BeansException;
2827
import org.springframework.beans.factory.BeanFactory;
2928
import org.springframework.beans.factory.HierarchicalBeanFactory;
@@ -107,28 +106,26 @@ public class DefaultConfiguringBeanFactoryPostProcessor
107106

108107
@Override
109108
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
110-
if (!AotDetector.useGeneratedArtifacts()) {
111-
this.registry = registry;
112-
this.beanFactory = (ConfigurableListableBeanFactory) registry;
113-
114-
registerBeanFactoryChannelResolver();
115-
registerMessagePublishingErrorHandler();
116-
registerNullChannel();
117-
registerErrorChannel();
118-
registerIntegrationEvaluationContext();
119-
registerTaskScheduler();
120-
registerIdGeneratorConfigurer();
121-
registerIntegrationProperties();
122-
registerBuiltInBeans();
123-
registerRoleController();
124-
registerMessageBuilderFactory();
125-
registerHeaderChannelRegistry();
126-
registerGlobalChannelInterceptorProcessor();
127-
registerDefaultDatatypeChannelMessageConverter();
128-
registerArgumentResolverMessageConverter();
129-
registerMessageHandlerMethodFactory();
130-
registerListMessageHandlerMethodFactory();
131-
}
109+
this.registry = registry;
110+
this.beanFactory = (ConfigurableListableBeanFactory) registry;
111+
112+
registerBeanFactoryChannelResolver();
113+
registerMessagePublishingErrorHandler();
114+
registerNullChannel();
115+
registerErrorChannel();
116+
registerIntegrationEvaluationContext();
117+
registerTaskScheduler();
118+
registerIdGeneratorConfigurer();
119+
registerIntegrationProperties();
120+
registerBuiltInBeans();
121+
registerRoleController();
122+
registerMessageBuilderFactory();
123+
registerHeaderChannelRegistry();
124+
registerGlobalChannelInterceptorProcessor();
125+
registerDefaultDatatypeChannelMessageConverter();
126+
registerArgumentResolverMessageConverter();
127+
registerMessageHandlerMethodFactory();
128+
registerListMessageHandlerMethodFactory();
132129
}
133130

134131
@Override

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationBeanFactoryPostProcessor.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.List;
2020

21-
import org.springframework.aot.AotDetector;
2221
import org.springframework.beans.BeansException;
2322
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2423
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -39,16 +38,14 @@ public class IntegrationConfigurationBeanFactoryPostProcessor implements BeanDef
3938

4039
@Override
4140
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
42-
if (!AotDetector.useGeneratedArtifacts()) {
43-
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) registry;
41+
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) registry;
4442

45-
List<IntegrationConfigurationInitializer> initializers =
46-
SpringFactoriesLoader.loadFactories(IntegrationConfigurationInitializer.class,
47-
beanFactory.getBeanClassLoader());
43+
List<IntegrationConfigurationInitializer> initializers =
44+
SpringFactoriesLoader.loadFactories(IntegrationConfigurationInitializer.class,
45+
beanFactory.getBeanClassLoader());
4846

49-
for (IntegrationConfigurationInitializer initializer : initializers) {
50-
initializer.initialize(beanFactory);
51-
}
47+
for (IntegrationConfigurationInitializer initializer : initializers) {
48+
initializer.initialize(beanFactory);
5249
}
5350
}
5451

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar=org.springframework.integration.aot.CoreRuntimeHints
22
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=org.springframework.integration.aot.GatewayProxyBeanRegistrationAotProcessor
3+
org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter=org.springframework.integration.aot.IntegrationBeanRegistrationExcludeFilter

0 commit comments

Comments
 (0)