From 5fb4103a2587ef98bafaef7a51e712250f9a753e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 20 Dec 2016 12:35:17 +0100 Subject: [PATCH] Polishing --- .../ConfigurationClassPostProcessor.java | 12 ++++---- .../configuration/Spr10668Tests.java | 28 ++++++------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java index 301256a6a8..6d08dfc71d 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java @@ -37,7 +37,6 @@ import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; @@ -91,12 +90,12 @@ import static org.springframework.context.annotation.AnnotationConfigUtils.*; public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor, PriorityOrdered, ResourceLoaderAware, BeanClassLoaderAware, EnvironmentAware { - private static final String IMPORT_AWARE_PROCESSOR_BEAN_NAME = - ConfigurationClassPostProcessor.class.getName() + ".importAwareProcessor"; - private static final String IMPORT_REGISTRY_BEAN_NAME = ConfigurationClassPostProcessor.class.getName() + ".importRegistry"; + private static final String IMPORT_AWARE_PROCESSOR_BEAN_NAME = + ConfigurationClassPostProcessor.class.getName() + ".importAwareProcessor"; + private static final String ENHANCED_CONFIGURATION_PROCESSOR_BEAN_NAME = ConfigurationClassPostProcessor.class.getName() + ".enhancedConfigurationProcessor"; @@ -260,6 +259,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo // Simply call processConfigurationClasses lazily at this point then. processConfigBeanDefinitions((BeanDefinitionRegistry) beanFactory); } + enhanceConfigurationClasses(beanFactory); } @@ -455,10 +455,10 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo /** * {@link InstantiationAwareBeanPostProcessorAdapter} that ensures * {@link EnhancedConfiguration} beans are injected with the {@link BeanFactory} - * before the {@link AutowiredAnnotationBeanPostProcessor} runs (SPR-10668). + * before the {@code AutowiredAnnotationBeanPostProcessor} runs (SPR-10668). */ private static class EnhancedConfigurationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter - implements PriorityOrdered, BeanFactoryAware { + implements BeanFactoryAware, PriorityOrdered { private BeanFactory beanFactory; diff --git a/spring-context/src/test/java/org/springframework/context/annotation/configuration/Spr10668Tests.java b/spring-context/src/test/java/org/springframework/context/annotation/configuration/Spr10668Tests.java index c00c2edb0f..f3868bea67 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/configuration/Spr10668Tests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/configuration/Spr10668Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 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,29 +38,20 @@ public class Spr10668Tests { @Test public void testSelfInjectHierarchy() throws Exception { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( - ChildConfig.class); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ChildConfig.class); assertNotNull(context.getBean(MyComponent.class)); context.close(); } + @Configuration - public static class ParentConfig implements BeanFactoryAware { + public static class ParentConfig { @Autowired(required = false) MyComponent component; - - public ParentConfig() { - System.out.println("Parent " + getClass()); - } - - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - System.out.println("BFA " + getClass()); - } - } + @Configuration public static class ChildConfig extends ParentConfig { @@ -68,12 +59,11 @@ public class Spr10668Tests { public MyComponentImpl myComponent() { return new MyComponentImpl(); } - } - public static interface MyComponent { - } - public static class MyComponentImpl implements MyComponent { - } + public interface MyComponent {} + + public static class MyComponentImpl implements MyComponent {} + }