Browse Source

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
pull/752/head
Stephane Nicoll 10 years ago
parent
commit
31df7155ab
  1. 13
      spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java
  2. 3
      spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java
  3. 3
      spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
  4. 3
      spring-jms/src/main/java/org/springframework/jms/annotation/JmsBootstrapConfiguration.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; @@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@ -303,7 +304,7 @@ class PostProcessorRegistrationDelegate { @@ -303,7 +304,7 @@ class PostProcessorRegistrationDelegate {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean != null && !(bean instanceof BeanPostProcessor) &&
if (bean != null && !(bean instanceof BeanPostProcessor) && !isInfrastructureBean(beanName) &&
this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount) {
if (logger.isInfoEnabled()) {
logger.info("Bean '" + beanName + "' of type [" + bean.getClass() +
@ -313,6 +314,14 @@ class PostProcessorRegistrationDelegate { @@ -313,6 +314,14 @@ class PostProcessorRegistrationDelegate {
}
return bean;
}
private boolean isInfrastructureBean(String beanName) {
if (beanName != null && this.beanFactory.containsBean(beanName)) {
BeanDefinition bd = this.beanFactory.getBeanDefinition(beanName);
return RootBeanDefinition.ROLE_INFRASTRUCTURE == bd.getRole();
}
return false;
}
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,6 +37,7 @@ import org.springframework.util.Assert; @@ -37,6 +37,7 @@ import org.springframework.util.Assert;
* @see AsyncConfigurationSelector
*/
@Configuration
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
@Bean(name = TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,6 +37,7 @@ import org.springframework.scheduling.config.TaskManagementConfigUtils; @@ -37,6 +37,7 @@ import org.springframework.scheduling.config.TaskManagementConfigUtils;
* @see ScheduledAnnotationBeanPostProcessor
*/
@Configuration
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class SchedulingConfiguration {
@Bean(name = TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -38,6 +38,7 @@ import org.springframework.jms.config.JmsListenerEndpointRegistry; @@ -38,6 +38,7 @@ import org.springframework.jms.config.JmsListenerEndpointRegistry;
* @see EnableJms
*/
@Configuration
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class JmsBootstrapConfiguration {
@Bean(name = JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)

Loading…
Cancel
Save