public class SimplePortletPostProcessor extends java.lang.Object implements DestructionAwareBeanPostProcessor, PortletContextAware, PortletConfigAware
BeanPostProcessor
that applies initialization and destruction callbacks to beans that
implement the Portlet interface.
After initialization of the bean instance, the Portlet init
method will be called with a PortletConfig that contains the bean name
of the Portlet and the PortletContext that it is running in.
Before destruction of the bean instance, the Portlet destroy
will be called.
Note that this post-processor does not support Portlet initialization parameters. Bean instances that implement the Portlet interface are supposed to be configured like any other Spring bean, that is, through constructor arguments or bean properties.
For reuse of a Portlet implementation in a plain Portlet container
and as a bean in a Spring context, consider deriving from Spring's
GenericPortletBean base class that
applies Portlet initialization parameters as bean properties, supporting
both the standard Portlet and the Spring bean initialization style.
Alternatively, consider wrapping a Portlet with Spring's
PortletWrappingController.
This is particularly appropriate for existing Portlet classes,
allowing to specify Portlet initialization parameters etc.
Portlet,
PortletConfig,
SimplePortletHandlerAdapter,
GenericPortletBean,
PortletWrappingController| Constructor and Description |
|---|
SimplePortletPostProcessor() |
| Modifier and Type | Method and Description |
|---|---|
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). |
boolean |
requiresDestruction(java.lang.Object bean)
Determine whether the given bean instance requires destruction by this
post-processor.
|
void |
setPortletConfig(PortletConfig portletConfig)
Set the PortletConfigthat this object runs in.
|
void |
setPortletContext(PortletContext portletContext)
Set the PortletContext that this object runs in.
|
void |
setUseSharedPortletConfig(boolean useSharedPortletConfig)
Set whether to use the shared PortletConfig object passed in
through
setPortletConfig, if available. |
public void setUseSharedPortletConfig(boolean useSharedPortletConfig)
setPortletConfig, if available.
Default is "true". Turn this setting to "false" to pass in a mock PortletConfig object with the bean name as portlet name, holding the current PortletContext.
public void setPortletContext(PortletContext portletContext)
PortletContextAwareInvoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.
setPortletContext in interface PortletContextAwareportletContext - PortletContext object to be used by this objectpublic void setPortletConfig(PortletConfig portletConfig)
PortletConfigAwareInvoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.
setPortletConfig in interface PortletConfigAwareportletConfig - PortletConfig object to be used by this objectpublic java.lang.Object postProcessBeforeInitialization(java.lang.Object bean,
java.lang.String beanName)
throws BeansException
BeanPostProcessorafterPropertiesSet
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.postProcessBeforeInitialization in interface BeanPostProcessorbean - the new bean instancebeanName - the name of the beannull, no subsequent BeanPostProcessors will be invokedBeansException - in case of errorsInitializingBean.afterPropertiesSet()public java.lang.Object postProcessAfterInitialization(java.lang.Object bean,
java.lang.String beanName)
throws BeansException
BeanPostProcessorafterPropertiesSet
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.
postProcessAfterInitialization in interface BeanPostProcessorbean - the new bean instancebeanName - the name of the beannull, no subsequent BeanPostProcessors will be invokedBeansException - in case of errorsInitializingBean.afterPropertiesSet(),
FactoryBeanpublic void postProcessBeforeDestruction(java.lang.Object bean,
java.lang.String beanName)
throws BeansException
DestructionAwareBeanPostProcessorLike DisposableBean's destroy and a custom destroy method,
this callback just applies to singleton beans in the factory (including
inner beans).
postProcessBeforeDestruction in interface DestructionAwareBeanPostProcessorbean - the bean instance to be destroyedbeanName - the name of the beanBeansException - in case of errorsDisposableBean,
AbstractBeanDefinition.setDestroyMethodName(java.lang.String)public boolean requiresDestruction(java.lang.Object bean)
DestructionAwareBeanPostProcessorNOTE: 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 DestructionAwareBeanPostProcessorbean - 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 needed