diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index c5a47b891a..82fbbeba52 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -379,6 +379,7 @@ class ConfigurationClassParser { // the candidate class is an ImportSelector -> delegate to it to determine imports Class candidateClass = (candidate instanceof Class ? (Class) candidate : this.resourceLoader.getClassLoader().loadClass((String) candidate)); ImportSelector selector = BeanUtils.instantiateClass(candidateClass, ImportSelector.class); + invokeAwareMethods(selector); processImport(configClass, Arrays.asList(selector.selectImports(importingClassMetadata)), false); } else if (checkAssignability(ImportBeanDefinitionRegistrar.class, candidateToCheck)) { @@ -416,21 +417,21 @@ class ConfigurationClassParser { /** * Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and - * {@link BeanFactoryAware} contracts if implemented by the given {@code registrar}. + * {@link BeanFactoryAware} contracts if implemented by the given {@code bean}. */ - private void invokeAwareMethods(ImportBeanDefinitionRegistrar registrar) { - if (registrar instanceof Aware) { - if (registrar instanceof ResourceLoaderAware) { - ((ResourceLoaderAware) registrar).setResourceLoader(this.resourceLoader); + private void invokeAwareMethods(Object importStrategyBean) { + if (importStrategyBean instanceof Aware) { + if (importStrategyBean instanceof ResourceLoaderAware) { + ((ResourceLoaderAware) importStrategyBean).setResourceLoader(this.resourceLoader); } - if (registrar instanceof BeanClassLoaderAware) { + if (importStrategyBean instanceof BeanClassLoaderAware) { ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ? ((ConfigurableBeanFactory) this.registry).getBeanClassLoader() : this.resourceLoader.getClassLoader()); - ((BeanClassLoaderAware) registrar).setBeanClassLoader(classLoader); + ((BeanClassLoaderAware) importStrategyBean).setBeanClassLoader(classLoader); } - if (registrar instanceof BeanFactoryAware && this.registry instanceof BeanFactory) { - ((BeanFactoryAware) registrar).setBeanFactory((BeanFactory) this.registry); + if (importStrategyBean instanceof BeanFactoryAware && this.registry instanceof BeanFactory) { + ((BeanFactoryAware) importStrategyBean).setBeanFactory((BeanFactory) this.registry); } } } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java b/spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java index 802dde7083..5fcb9b960f 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2013 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. @@ -23,6 +23,15 @@ import org.springframework.core.type.AnnotationMetadata; * class(es) should be imported based on a given selection criteria, usually one or more * annotation attributes. * + *

An {@link ImportSelector} may implement any of the following + * {@link org.springframework.beans.factory.Aware Aware} interfaces, and their respective + * methods will be called prior to {@link #selectImports}: + *

+ * * @author Chris Beams * @since 3.1 * @see Import