Skip to content

Commit 13980af

Browse files
authored
GH-8611: Extract IntegrationConfigurationReport (#8660)
Fixes #8611 According to the latest Spring Framework requirements related to AOT the `BeanDefinitionRegistryPostProcessor` must not do anything but only bean registrations * Extract an `IntegrationConfigurationReport` component and move `IntegrationProperties` printing over here out from the `DefaultConfiguringBeanFactoryPostProcessor` * Remove a `SmartInitializingSingleton` impl from the `DefaultConfiguringBeanFactoryPostProcessor`
1 parent 65c7e5d commit 13980af

File tree

2 files changed

+87
-21
lines changed

2 files changed

+87
-21
lines changed

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616

1717
package org.springframework.integration.config;
1818

19-
import java.io.PrintWriter;
20-
import java.io.StringWriter;
19+
import java.beans.Introspector;
2120
import java.util.HashSet;
22-
import java.util.Properties;
2321
import java.util.Set;
2422
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
2523

2624
import org.springframework.beans.BeansException;
2725
import org.springframework.beans.factory.BeanFactory;
2826
import org.springframework.beans.factory.HierarchicalBeanFactory;
29-
import org.springframework.beans.factory.SmartInitializingSingleton;
3027
import org.springframework.beans.factory.config.BeanDefinition;
3128
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3229
import org.springframework.beans.factory.config.PropertiesFactoryBean;
@@ -74,8 +71,7 @@
7471
*
7572
* @see IntegrationContextUtils
7673
*/
77-
public class DefaultConfiguringBeanFactoryPostProcessor
78-
implements BeanDefinitionRegistryPostProcessor, SmartInitializingSingleton {
74+
public class DefaultConfiguringBeanFactoryPostProcessor implements BeanDefinitionRegistryPostProcessor {
7975

8076
private static final LogAccessor LOGGER = new LogAccessor(DefaultConfiguringBeanFactoryPostProcessor.class);
8177

@@ -130,27 +126,13 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t
130126
registerArgumentResolverMessageConverter();
131127
registerMessageHandlerMethodFactory();
132128
registerListMessageHandlerMethodFactory();
129+
registerIntegrationConfigurationReport();
133130
}
134131

135132
@Override
136133
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
137134
}
138135

139-
@Override
140-
public void afterSingletonsInstantiated() {
141-
if (LOGGER.isDebugEnabled()) {
142-
Properties integrationProperties =
143-
IntegrationContextUtils.getIntegrationProperties(this.beanFactory)
144-
.toProperties();
145-
146-
StringWriter writer = new StringWriter();
147-
integrationProperties.list(new PrintWriter(writer));
148-
StringBuffer propertiesBuffer = writer.getBuffer()
149-
.delete(0, "-- listing properties --".length());
150-
LOGGER.debug("\nSpring Integration global properties:\n" + propertiesBuffer);
151-
}
152-
}
153-
154136
private void registerBeanFactoryChannelResolver() {
155137
if (!this.beanFactory.containsBeanDefinition(ChannelResolverUtils.CHANNEL_RESOLVER_BEAN_NAME)) {
156138
this.registry.registerBeanDefinition(ChannelResolverUtils.CHANNEL_RESOLVER_BEAN_NAME,
@@ -450,6 +432,13 @@ private void registerListMessageHandlerMethodFactory() {
450432
}
451433
}
452434

435+
private void registerIntegrationConfigurationReport() {
436+
this.registry.registerBeanDefinition(Introspector.decapitalize(IntegrationConfigurationReport.class.getName()),
437+
BeanDefinitionBuilder.genericBeanDefinition(IntegrationConfigurationReport.class)
438+
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
439+
.getBeanDefinition());
440+
}
441+
453442
private static BeanDefinitionBuilder createMessageHandlerMethodFactoryBeanDefinition(boolean listCapable) {
454443
return BeanDefinitionBuilder.genericBeanDefinition(IntegrationMessageHandlerMethodFactory.class)
455444
.addConstructorArgValue(listCapable)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2023 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.config;
18+
19+
20+
import java.io.PrintWriter;
21+
import java.io.StringWriter;
22+
import java.util.Properties;
23+
24+
import org.springframework.beans.BeansException;
25+
import org.springframework.context.ApplicationContext;
26+
import org.springframework.context.ApplicationContextAware;
27+
import org.springframework.context.ApplicationListener;
28+
import org.springframework.context.event.ContextRefreshedEvent;
29+
import org.springframework.core.log.LogAccessor;
30+
import org.springframework.integration.context.IntegrationContextUtils;
31+
32+
/**
33+
* An {@link org.springframework.beans.factory.config.BeanDefinition#ROLE_INFRASTRUCTURE}
34+
* component to report Spring Integration relevant configuration state after application context is refreshed.
35+
*
36+
* @author Artem Bilan
37+
*
38+
* @since 6.2
39+
*/
40+
class IntegrationConfigurationReport
41+
implements ApplicationContextAware, ApplicationListener<ContextRefreshedEvent> {
42+
43+
private static final LogAccessor LOGGER = new LogAccessor(IntegrationConfigurationReport.class);
44+
45+
private ApplicationContext applicationContext;
46+
47+
@Override
48+
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
49+
this.applicationContext = applicationContext;
50+
}
51+
52+
@Override
53+
public void onApplicationEvent(ContextRefreshedEvent event) {
54+
if (event.getApplicationContext().equals(this.applicationContext)) {
55+
report();
56+
}
57+
}
58+
59+
private void report() {
60+
printIntegrationProperties();
61+
}
62+
63+
private void printIntegrationProperties() {
64+
if (LOGGER.isDebugEnabled()) {
65+
Properties integrationProperties =
66+
IntegrationContextUtils.getIntegrationProperties(this.applicationContext)
67+
.toProperties();
68+
69+
StringWriter writer = new StringWriter();
70+
integrationProperties.list(new PrintWriter(writer));
71+
StringBuffer propertiesBuffer = writer.getBuffer()
72+
.delete(0, "-- listing properties --".length());
73+
LOGGER.debug("\nSpring Integration global properties:\n" + propertiesBuffer);
74+
}
75+
}
76+
77+
}

0 commit comments

Comments
 (0)