Skip to content

Commit 7538561

Browse files
committed
Polish ApplicationContextAwareProcessor
Due to recent changes, the (bean instanceof Aware) check is now superfluous.
1 parent 6c0e550 commit 7538561

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.security.PrivilegedAction;
2222

2323
import org.springframework.beans.BeansException;
24-
import org.springframework.beans.factory.Aware;
2524
import org.springframework.beans.factory.config.BeanPostProcessor;
2625
import org.springframework.beans.factory.config.EmbeddedValueResolver;
2726
import org.springframework.context.ApplicationContextAware;
@@ -35,13 +34,15 @@
3534
import org.springframework.util.StringValueResolver;
3635

3736
/**
38-
* {@link org.springframework.beans.factory.config.BeanPostProcessor}
39-
* implementation that passes the ApplicationContext to beans that
37+
* {@link BeanPostProcessor} implementation that supplies the {@code ApplicationContext},
38+
* {@link org.springframework.core.env.Environment Environment}, or
39+
* {@link StringValueResolver} for the {@code ApplicationContext} to beans that
4040
* implement the {@link EnvironmentAware}, {@link EmbeddedValueResolverAware},
4141
* {@link ResourceLoaderAware}, {@link ApplicationEventPublisherAware},
42-
* {@link MessageSourceAware} and/or {@link ApplicationContextAware} interfaces.
42+
* {@link MessageSourceAware}, and/or {@link ApplicationContextAware} interfaces.
4343
*
44-
* <p>Implemented interfaces are satisfied in order of their mention above.
44+
* <p>Implemented interfaces are satisfied in the order in which they are
45+
* mentioned above.
4546
*
4647
* <p>Application contexts will automatically register this with their
4748
* underlying bean factory. Applications do not use this directly.
@@ -103,25 +104,23 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
103104
}
104105

105106
private void invokeAwareInterfaces(Object bean) {
106-
if (bean instanceof Aware) {
107-
if (bean instanceof EnvironmentAware) {
108-
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
109-
}
110-
if (bean instanceof EmbeddedValueResolverAware) {
111-
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
112-
}
113-
if (bean instanceof ResourceLoaderAware) {
114-
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
115-
}
116-
if (bean instanceof ApplicationEventPublisherAware) {
117-
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
118-
}
119-
if (bean instanceof MessageSourceAware) {
120-
((MessageSourceAware) bean).setMessageSource(this.applicationContext);
121-
}
122-
if (bean instanceof ApplicationContextAware) {
123-
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
124-
}
107+
if (bean instanceof EnvironmentAware) {
108+
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
109+
}
110+
if (bean instanceof EmbeddedValueResolverAware) {
111+
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
112+
}
113+
if (bean instanceof ResourceLoaderAware) {
114+
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
115+
}
116+
if (bean instanceof ApplicationEventPublisherAware) {
117+
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
118+
}
119+
if (bean instanceof MessageSourceAware) {
120+
((MessageSourceAware) bean).setMessageSource(this.applicationContext);
121+
}
122+
if (bean instanceof ApplicationContextAware) {
123+
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
125124
}
126125
}
127126

0 commit comments

Comments
 (0)