1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
32
32
import org .springframework .util .StringValueResolver ;
33
33
34
34
/**
35
- * {@link BeanPostProcessor} implementation that supplies the {@code ApplicationContext},
36
- * {@link org.springframework.core.env.Environment Environment}, or
37
- * {@link StringValueResolver} for the {@code ApplicationContext} to beans that
38
- * implement the {@link EnvironmentAware}, {@link EmbeddedValueResolverAware},
39
- * {@link ResourceLoaderAware}, {@link ApplicationEventPublisherAware},
40
- * {@link MessageSourceAware}, and/or {@link ApplicationContextAware} interfaces.
35
+ * {@link BeanPostProcessor} implementation that supplies the
36
+ * {@link org.springframework.context.ApplicationContext ApplicationContext},
37
+ * {@link org.springframework.core.env.Environment Environment},
38
+ * {@link StringValueResolver}, or
39
+ * {@link org.springframework.core.metrics.ApplicationStartup ApplicationStartup}
40
+ * for the {@code ApplicationContext} to beans that implement the {@link EnvironmentAware},
41
+ * {@link EmbeddedValueResolverAware}, {@link ResourceLoaderAware},
42
+ * {@link ApplicationEventPublisherAware}, {@link MessageSourceAware},
43
+ * {@link ApplicationStartupAware}, and/or {@link ApplicationContextAware} interfaces.
41
44
*
42
45
* <p>Implemented interfaces are satisfied in the order in which they are
43
46
* mentioned above.
55
58
* @see org.springframework.context.ResourceLoaderAware
56
59
* @see org.springframework.context.ApplicationEventPublisherAware
57
60
* @see org.springframework.context.MessageSourceAware
61
+ * @see org.springframework.context.ApplicationStartupAware
58
62
* @see org.springframework.context.ApplicationContextAware
59
63
* @see org.springframework.context.support.AbstractApplicationContext#refresh()
60
64
*/
@@ -77,10 +81,10 @@ public ApplicationContextAwareProcessor(ConfigurableApplicationContext applicati
77
81
@ Override
78
82
@ Nullable
79
83
public Object postProcessBeforeInitialization (Object bean , String beanName ) throws BeansException {
80
- if (!(bean instanceof EnvironmentAware || bean instanceof EmbeddedValueResolverAware ||
84
+ if (!(( bean instanceof Aware ) && ( bean instanceof EnvironmentAware || bean instanceof EmbeddedValueResolverAware ||
81
85
bean instanceof ResourceLoaderAware || bean instanceof ApplicationEventPublisherAware ||
82
- bean instanceof MessageSourceAware || bean instanceof ApplicationContextAware ||
83
- bean instanceof ApplicationStartupAware )) {
86
+ bean instanceof MessageSourceAware || bean instanceof ApplicationStartupAware ||
87
+ bean instanceof ApplicationContextAware ) )) {
84
88
return bean ;
85
89
}
86
90
@@ -89,28 +93,26 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
89
93
}
90
94
91
95
private void invokeAwareInterfaces (Object bean ) {
92
- if (bean instanceof Aware ) {
93
- if (bean instanceof EnvironmentAware environmentAware ) {
94
- environmentAware .setEnvironment (this .applicationContext .getEnvironment ());
95
- }
96
- if (bean instanceof EmbeddedValueResolverAware embeddedValueResolverAware ) {
97
- embeddedValueResolverAware .setEmbeddedValueResolver (this .embeddedValueResolver );
98
- }
99
- if (bean instanceof ResourceLoaderAware resourceLoaderAware ) {
100
- resourceLoaderAware .setResourceLoader (this .applicationContext );
101
- }
102
- if (bean instanceof ApplicationEventPublisherAware applicationEventPublisherAware ) {
103
- applicationEventPublisherAware .setApplicationEventPublisher (this .applicationContext );
104
- }
105
- if (bean instanceof MessageSourceAware messageSourceAware ) {
106
- messageSourceAware .setMessageSource (this .applicationContext );
107
- }
108
- if (bean instanceof ApplicationStartupAware applicationStartupAware ) {
109
- applicationStartupAware .setApplicationStartup (this .applicationContext .getApplicationStartup ());
110
- }
111
- if (bean instanceof ApplicationContextAware applicationContextAware ) {
112
- applicationContextAware .setApplicationContext (this .applicationContext );
113
- }
96
+ if (bean instanceof EnvironmentAware environmentAware ) {
97
+ environmentAware .setEnvironment (this .applicationContext .getEnvironment ());
98
+ }
99
+ if (bean instanceof EmbeddedValueResolverAware embeddedValueResolverAware ) {
100
+ embeddedValueResolverAware .setEmbeddedValueResolver (this .embeddedValueResolver );
101
+ }
102
+ if (bean instanceof ResourceLoaderAware resourceLoaderAware ) {
103
+ resourceLoaderAware .setResourceLoader (this .applicationContext );
104
+ }
105
+ if (bean instanceof ApplicationEventPublisherAware applicationEventPublisherAware ) {
106
+ applicationEventPublisherAware .setApplicationEventPublisher (this .applicationContext );
107
+ }
108
+ if (bean instanceof MessageSourceAware messageSourceAware ) {
109
+ messageSourceAware .setMessageSource (this .applicationContext );
110
+ }
111
+ if (bean instanceof ApplicationStartupAware applicationStartupAware ) {
112
+ applicationStartupAware .setApplicationStartup (this .applicationContext .getApplicationStartup ());
113
+ }
114
+ if (bean instanceof ApplicationContextAware applicationContextAware ) {
115
+ applicationContextAware .setApplicationContext (this .applicationContext );
114
116
}
115
117
}
116
118
0 commit comments