Polish ApplicationContextAwareProcessor
This commit is contained in:
parent
f726e806cd
commit
1080c145e3
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,12 +32,15 @@ import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.StringValueResolver;
|
import org.springframework.util.StringValueResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link BeanPostProcessor} implementation that supplies the {@code ApplicationContext},
|
* {@link BeanPostProcessor} implementation that supplies the
|
||||||
* {@link org.springframework.core.env.Environment Environment}, or
|
* {@link org.springframework.context.ApplicationContext ApplicationContext},
|
||||||
* {@link StringValueResolver} for the {@code ApplicationContext} to beans that
|
* {@link org.springframework.core.env.Environment Environment},
|
||||||
* implement the {@link EnvironmentAware}, {@link EmbeddedValueResolverAware},
|
* {@link StringValueResolver}, or
|
||||||
* {@link ResourceLoaderAware}, {@link ApplicationEventPublisherAware},
|
* {@link org.springframework.core.metrics.ApplicationStartup ApplicationStartup}
|
||||||
* {@link MessageSourceAware}, and/or {@link ApplicationContextAware} interfaces.
|
* for the {@code ApplicationContext} to beans that implement the {@link EnvironmentAware},
|
||||||
|
* {@link EmbeddedValueResolverAware}, {@link ResourceLoaderAware},
|
||||||
|
* {@link ApplicationEventPublisherAware}, {@link MessageSourceAware},
|
||||||
|
* {@link ApplicationStartupAware}, and/or {@link ApplicationContextAware} interfaces.
|
||||||
*
|
*
|
||||||
* <p>Implemented interfaces are satisfied in the order in which they are
|
* <p>Implemented interfaces are satisfied in the order in which they are
|
||||||
* mentioned above.
|
* mentioned above.
|
||||||
|
@ -55,6 +58,7 @@ import org.springframework.util.StringValueResolver;
|
||||||
* @see org.springframework.context.ResourceLoaderAware
|
* @see org.springframework.context.ResourceLoaderAware
|
||||||
* @see org.springframework.context.ApplicationEventPublisherAware
|
* @see org.springframework.context.ApplicationEventPublisherAware
|
||||||
* @see org.springframework.context.MessageSourceAware
|
* @see org.springframework.context.MessageSourceAware
|
||||||
|
* @see org.springframework.context.ApplicationStartupAware
|
||||||
* @see org.springframework.context.ApplicationContextAware
|
* @see org.springframework.context.ApplicationContextAware
|
||||||
* @see org.springframework.context.support.AbstractApplicationContext#refresh()
|
* @see org.springframework.context.support.AbstractApplicationContext#refresh()
|
||||||
*/
|
*/
|
||||||
|
@ -77,10 +81,10 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||||
if (!(bean instanceof EnvironmentAware || bean instanceof EmbeddedValueResolverAware ||
|
if (!((bean instanceof Aware) && (bean instanceof EnvironmentAware || bean instanceof EmbeddedValueResolverAware ||
|
||||||
bean instanceof ResourceLoaderAware || bean instanceof ApplicationEventPublisherAware ||
|
bean instanceof ResourceLoaderAware || bean instanceof ApplicationEventPublisherAware ||
|
||||||
bean instanceof MessageSourceAware || bean instanceof ApplicationContextAware ||
|
bean instanceof MessageSourceAware || bean instanceof ApplicationStartupAware ||
|
||||||
bean instanceof ApplicationStartupAware)) {
|
bean instanceof ApplicationContextAware))) {
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +93,6 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeAwareInterfaces(Object bean) {
|
private void invokeAwareInterfaces(Object bean) {
|
||||||
if (bean instanceof Aware) {
|
|
||||||
if (bean instanceof EnvironmentAware environmentAware) {
|
if (bean instanceof EnvironmentAware environmentAware) {
|
||||||
environmentAware.setEnvironment(this.applicationContext.getEnvironment());
|
environmentAware.setEnvironment(this.applicationContext.getEnvironment());
|
||||||
}
|
}
|
||||||
|
@ -112,6 +115,5 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
|
||||||
applicationContextAware.setApplicationContext(this.applicationContext);
|
applicationContextAware.setApplicationContext(this.applicationContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue