Polish ApplicationContextAwareProcessor
Due to recent changes, the (bean instanceof Aware) check is now superfluous.
This commit is contained in:
parent
6c0e550b86
commit
7538561a7a
|
|
@ -21,7 +21,6 @@ import java.security.AccessController;
|
|||
import java.security.PrivilegedAction;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.Aware;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.EmbeddedValueResolver;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
|
@ -35,13 +34,15 @@ import org.springframework.lang.Nullable;
|
|||
import org.springframework.util.StringValueResolver;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.beans.factory.config.BeanPostProcessor}
|
||||
* implementation that passes the ApplicationContext to beans that
|
||||
* {@link BeanPostProcessor} implementation that supplies the {@code ApplicationContext},
|
||||
* {@link org.springframework.core.env.Environment Environment}, or
|
||||
* {@link StringValueResolver} for the {@code ApplicationContext} to beans that
|
||||
* implement the {@link EnvironmentAware}, {@link EmbeddedValueResolverAware},
|
||||
* {@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
|
||||
* underlying bean factory. Applications do not use this directly.
|
||||
|
|
@ -103,25 +104,23 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
|
|||
}
|
||||
|
||||
private void invokeAwareInterfaces(Object bean) {
|
||||
if (bean instanceof Aware) {
|
||||
if (bean instanceof EnvironmentAware) {
|
||||
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
|
||||
}
|
||||
if (bean instanceof EmbeddedValueResolverAware) {
|
||||
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
|
||||
}
|
||||
if (bean instanceof ResourceLoaderAware) {
|
||||
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof ApplicationEventPublisherAware) {
|
||||
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof MessageSourceAware) {
|
||||
((MessageSourceAware) bean).setMessageSource(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof ApplicationContextAware) {
|
||||
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof EnvironmentAware) {
|
||||
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
|
||||
}
|
||||
if (bean instanceof EmbeddedValueResolverAware) {
|
||||
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
|
||||
}
|
||||
if (bean instanceof ResourceLoaderAware) {
|
||||
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof ApplicationEventPublisherAware) {
|
||||
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof MessageSourceAware) {
|
||||
((MessageSourceAware) bean).setMessageSource(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof ApplicationContextAware) {
|
||||
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue