Skip to content

Commit 31df715

Browse files
committed
Refine BeanPostProcessorChecker condition
Previously, adding `@EnableAsync` on a blank application would lead to an info message stating that `ProxyAsyncConfiguration` is not eligible for getting processed by all BeanPostProcessors. Concretely, this is ok as such internal configuration is not meant to be a target of such post processing. Revisit the condition for non infrastructure bean only. Add the infrastructure role to a set of internal configuration, including the `ProxyAsyncConfiguration`. Issue: SPR-12761
1 parent 5c9f09c commit 31df715

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import org.apache.commons.logging.Log;
2929
import org.apache.commons.logging.LogFactory;
3030

31+
import org.springframework.beans.factory.config.BeanDefinition;
3132
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
3233
import org.springframework.beans.factory.config.BeanPostProcessor;
3334
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -303,7 +304,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) {
303304

304305
@Override
305306
public Object postProcessAfterInitialization(Object bean, String beanName) {
306-
if (bean != null && !(bean instanceof BeanPostProcessor) &&
307+
if (bean != null && !(bean instanceof BeanPostProcessor) && !isInfrastructureBean(beanName) &&
307308
this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount) {
308309
if (logger.isInfoEnabled()) {
309310
logger.info("Bean '" + beanName + "' of type [" + bean.getClass() +
@@ -313,6 +314,14 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
313314
}
314315
return bean;
315316
}
317+
318+
private boolean isInfrastructureBean(String beanName) {
319+
if (beanName != null && this.beanFactory.containsBean(beanName)) {
320+
BeanDefinition bd = this.beanFactory.getBeanDefinition(beanName);
321+
return RootBeanDefinition.ROLE_INFRASTRUCTURE == bd.getRole();
322+
}
323+
return false;
324+
}
316325
}
317326

318327

spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
* @see AsyncConfigurationSelector
3838
*/
3939
@Configuration
40+
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
4041
public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
4142

4243
@Bean(name = TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)

spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
* @see ScheduledAnnotationBeanPostProcessor
3838
*/
3939
@Configuration
40+
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
4041
public class SchedulingConfiguration {
4142

4243
@Bean(name = TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)

spring-jms/src/main/java/org/springframework/jms/annotation/JmsBootstrapConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
3838
* @see EnableJms
3939
*/
4040
@Configuration
41+
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
4142
public class JmsBootstrapConfiguration {
4243

4344
@Bean(name = JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)

0 commit comments

Comments
 (0)