class ApplicationListenerDetector extends java.lang.Object implements DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor
BeanPostProcessor
that detects beans which implement the ApplicationListener
interface. This catches beans that can't reliably be detected by getBeanNamesForType
and related operations which only work against top-level beans.
With standard Java serialization, this post-processor won't get serialized as part of
DisposableBeanAdapter
to begin with. However, with alternative serialization
mechanisms, DisposableBeanAdapter.writeReplace
might not get used at all, so we
defensively mark this post-processor's field state as transient
.
Modifier and Type | Field and Description |
---|---|
private AbstractApplicationContext |
applicationContext |
private static Log |
logger |
private java.util.Map<java.lang.String,java.lang.Boolean> |
singletonNames |
Constructor and Description |
---|
ApplicationListenerDetector(AbstractApplicationContext applicationContext) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other) |
int |
hashCode() |
java.lang.Object |
postProcessAfterInitialization(java.lang.Object bean,
java.lang.String beanName)
Apply this BeanPostProcessor to the given new bean instance after any bean
initialization callbacks (like InitializingBean's
afterPropertiesSet
or a custom init-method). |
void |
postProcessBeforeDestruction(java.lang.Object bean,
java.lang.String beanName)
Apply this BeanPostProcessor to the given bean instance before
its destruction.
|
java.lang.Object |
postProcessBeforeInitialization(java.lang.Object bean,
java.lang.String beanName)
Apply this BeanPostProcessor to the given new bean instance before any bean
initialization callbacks (like InitializingBean's
afterPropertiesSet
or a custom init-method). |
void |
postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
java.lang.Class<?> beanType,
java.lang.String beanName)
Post-process the given merged bean definition for the specified bean.
|
boolean |
requiresDestruction(java.lang.Object bean)
Determine whether the given bean instance requires destruction by this
post-processor.
|
private static final Log logger
private final transient AbstractApplicationContext applicationContext
private final transient java.util.Map<java.lang.String,java.lang.Boolean> singletonNames
public ApplicationListenerDetector(AbstractApplicationContext applicationContext)
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, java.lang.Class<?> beanType, java.lang.String beanName)
MergedBeanDefinitionPostProcessor
postProcessMergedBeanDefinition
in interface MergedBeanDefinitionPostProcessor
beanDefinition
- the merged bean definition for the beanbeanType
- the actual type of the managed bean instancebeanName
- the name of the beanpublic java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName)
BeanPostProcessor
afterPropertiesSet
or a custom init-method). The bean will already be populated with property values.
The returned bean instance may be a wrapper around the original.
The default implementation returns the given bean
as-is.
postProcessBeforeInitialization
in interface BeanPostProcessor
bean
- the new bean instancebeanName
- the name of the beannull
, no subsequent BeanPostProcessors will be invokedInitializingBean.afterPropertiesSet()
public java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName)
BeanPostProcessor
afterPropertiesSet
or a custom init-method). The bean will already be populated with property values.
The returned bean instance may be a wrapper around the original.
In case of a FactoryBean, this callback will be invoked for both the FactoryBean
instance and the objects created by the FactoryBean (as of Spring 2.0). The
post-processor can decide whether to apply to either the FactoryBean or created
objects or both through corresponding bean instanceof FactoryBean
checks.
This callback will also be invoked after a short-circuiting triggered by a
InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)
method,
in contrast to all other BeanPostProcessor callbacks.
The default implementation returns the given bean
as-is.
postProcessAfterInitialization
in interface BeanPostProcessor
bean
- the new bean instancebeanName
- the name of the beannull
, no subsequent BeanPostProcessors will be invokedInitializingBean.afterPropertiesSet()
,
FactoryBean
public void postProcessBeforeDestruction(java.lang.Object bean, java.lang.String beanName)
DestructionAwareBeanPostProcessor
Like DisposableBean's destroy
and a custom destroy method,
this callback just applies to singleton beans in the factory (including
inner beans).
postProcessBeforeDestruction
in interface DestructionAwareBeanPostProcessor
bean
- the bean instance to be destroyedbeanName
- the name of the beanDisposableBean
,
AbstractBeanDefinition.setDestroyMethodName(java.lang.String)
public boolean requiresDestruction(java.lang.Object bean)
DestructionAwareBeanPostProcessor
NOTE: Even as a late addition, this method has been introduced on
DestructionAwareBeanPostProcessor
itself instead of on a SmartDABPP
subinterface. This allows existing DestructionAwareBeanPostProcessor
implementations to easily provide requiresDestruction
logic while
retaining compatibility with Spring <4.3, and it is also an easier onramp to
declaring requiresDestruction
as a Java 8 default method in Spring 5.
If an implementation of DestructionAwareBeanPostProcessor
does
not provide a concrete implementation of this method, Spring's invocation
mechanism silently assumes a method returning true
(the effective
default before 4.3, and the to-be-default in the Java 8 method in Spring 5).
requiresDestruction
in interface DestructionAwareBeanPostProcessor
bean
- the bean instance to checktrue
if DestructionAwareBeanPostProcessor.postProcessBeforeDestruction(java.lang.Object, java.lang.String)
is supposed to
be called for this bean instance eventually, or false
if not neededpublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object