Polish ApplicationContextAwareProcessor
Due to recent changes, the (bean instanceof Aware) check is now superfluous.
This commit is contained in:
@@ -21,7 +21,6 @@ import java.security.AccessController;
|
|||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.Aware;
|
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.beans.factory.config.EmbeddedValueResolver;
|
import org.springframework.beans.factory.config.EmbeddedValueResolver;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
@@ -35,13 +34,15 @@ import org.springframework.lang.Nullable;
|
|||||||
import org.springframework.util.StringValueResolver;
|
import org.springframework.util.StringValueResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.beans.factory.config.BeanPostProcessor}
|
* {@link BeanPostProcessor} implementation that supplies the {@code ApplicationContext},
|
||||||
* implementation that passes the ApplicationContext to beans that
|
* {@link org.springframework.core.env.Environment Environment}, or
|
||||||
|
* {@link StringValueResolver} for the {@code ApplicationContext} to beans that
|
||||||
* implement the {@link EnvironmentAware}, {@link EmbeddedValueResolverAware},
|
* implement the {@link EnvironmentAware}, {@link EmbeddedValueResolverAware},
|
||||||
* {@link ResourceLoaderAware}, {@link ApplicationEventPublisherAware},
|
* {@link ResourceLoaderAware}, {@link ApplicationEventPublisherAware},
|
||||||
* {@link MessageSourceAware} and/or {@link ApplicationContextAware} interfaces.
|
* {@link MessageSourceAware}, and/or {@link ApplicationContextAware} interfaces.
|
||||||
*
|
*
|
||||||
* <p>Implemented interfaces are satisfied in order of their mention above.
|
* <p>Implemented interfaces are satisfied in the order in which they are
|
||||||
|
* mentioned above.
|
||||||
*
|
*
|
||||||
* <p>Application contexts will automatically register this with their
|
* <p>Application contexts will automatically register this with their
|
||||||
* underlying bean factory. Applications do not use this directly.
|
* underlying bean factory. Applications do not use this directly.
|
||||||
@@ -103,25 +104,23 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void invokeAwareInterfaces(Object bean) {
|
private void invokeAwareInterfaces(Object bean) {
|
||||||
if (bean instanceof Aware) {
|
if (bean instanceof EnvironmentAware) {
|
||||||
if (bean instanceof EnvironmentAware) {
|
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
|
||||||
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
|
}
|
||||||
}
|
if (bean instanceof EmbeddedValueResolverAware) {
|
||||||
if (bean instanceof EmbeddedValueResolverAware) {
|
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
|
||||||
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
|
}
|
||||||
}
|
if (bean instanceof ResourceLoaderAware) {
|
||||||
if (bean instanceof ResourceLoaderAware) {
|
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
|
||||||
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
|
}
|
||||||
}
|
if (bean instanceof ApplicationEventPublisherAware) {
|
||||||
if (bean instanceof ApplicationEventPublisherAware) {
|
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
|
||||||
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
|
}
|
||||||
}
|
if (bean instanceof MessageSourceAware) {
|
||||||
if (bean instanceof MessageSourceAware) {
|
((MessageSourceAware) bean).setMessageSource(this.applicationContext);
|
||||||
((MessageSourceAware) bean).setMessageSource(this.applicationContext);
|
}
|
||||||
}
|
if (bean instanceof ApplicationContextAware) {
|
||||||
if (bean instanceof ApplicationContextAware) {
|
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
|
||||||
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user