public class SpringBeanAutowiringInterceptor
extends java.lang.Object
@Autowired
.
Performs injection after construction as well as after activation
of a passivated bean.
To be applied through an @Interceptors
annotation in
the EJB Session Bean or Message-Driven Bean class, or through an
interceptor-binding
XML element in the EJB deployment descriptor.
Delegates to Spring's AutowiredAnnotationBeanPostProcessor
underneath, allowing for customization of its specific settings through
overriding the configureBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor, java.lang.Object)
template method.
The actual BeanFactory to obtain Spring beans from is determined
by the getBeanFactory(java.lang.Object)
template method. The default implementation
obtains the Spring ContextSingletonBeanFactoryLocator
, initialized
from the default resource location classpath*:beanRefContext.xml,
and obtains the single ApplicationContext defined there.
NOTE: If you have more than one shared ApplicationContext definition available
in your EJB class loader, you need to override the getBeanFactoryLocatorKey(java.lang.Object)
method and provide a specific locator key for each autowired EJB.
Alternatively, override the getBeanFactory(java.lang.Object)
template method and
obtain the target factory explicitly.
WARNING: Do not define the same bean as Spring-managed bean and as
EJB3 session bean in the same deployment unit. In particular, be
careful when using the <context:component-scan>
feature
in combination with the deployment of Spring-based EJB3 session beans:
Make sure that the EJB3 session beans are not autodetected as
Spring-managed beans as well, using appropriate package restrictions.
Autowired
,
AutowiredAnnotationBeanPostProcessor
,
ContextSingletonBeanFactoryLocator
,
getBeanFactoryLocatorKey(java.lang.Object)
Constructor and Description |
---|
SpringBeanAutowiringInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
autowireBean(InvocationContext invocationContext)
Autowire the target bean after construction as well as after passivation.
|
protected void |
configureBeanPostProcessor(AutowiredAnnotationBeanPostProcessor processor,
java.lang.Object target)
Template method for configuring the
AutowiredAnnotationBeanPostProcessor used for autowiring. |
protected void |
doAutowireBean(java.lang.Object target)
Actually autowire the target bean after construction/passivation.
|
protected void |
doReleaseBean(java.lang.Object target)
Actually release the BeanFactoryReference for the given target bean.
|
protected BeanFactory |
getBeanFactory(java.lang.Object target)
Determine the BeanFactory for autowiring the given target bean.
|
protected BeanFactoryLocator |
getBeanFactoryLocator(java.lang.Object target)
Determine the BeanFactoryLocator to obtain the BeanFactoryReference from.
|
protected java.lang.String |
getBeanFactoryLocatorKey(java.lang.Object target)
Determine the BeanFactoryLocator key to use.
|
protected BeanFactoryReference |
getBeanFactoryReference(java.lang.Object target)
Determine the BeanFactoryReference for the given target bean.
|
void |
releaseBean(InvocationContext invocationContext)
Release the factory which has been used for autowiring the target bean.
|
@PostConstruct public void autowireBean(InvocationContext invocationContext)
invocationContext
- the EJB3 invocation contextprotected void doAutowireBean(java.lang.Object target)
target
- the target bean to autowireprotected void configureBeanPostProcessor(AutowiredAnnotationBeanPostProcessor processor, java.lang.Object target)
AutowiredAnnotationBeanPostProcessor
used for autowiring.processor
- the AutowiredAnnotationBeanPostProcessor to configuretarget
- the target bean to autowire with this processorprotected BeanFactory getBeanFactory(java.lang.Object target)
target
- the target bean to autowirenull
)getBeanFactoryReference(java.lang.Object)
protected BeanFactoryReference getBeanFactoryReference(java.lang.Object target)
The default implementation delegates to getBeanFactoryLocator(java.lang.Object)
and getBeanFactoryLocatorKey(java.lang.Object)
.
target
- the target bean to autowirenull
)getBeanFactoryLocator(java.lang.Object)
,
getBeanFactoryLocatorKey(java.lang.Object)
,
BeanFactoryLocator.useBeanFactory(String)
protected BeanFactoryLocator getBeanFactoryLocator(java.lang.Object target)
The default implementation exposes Spring's default
ContextSingletonBeanFactoryLocator
.
target
- the target bean to autowirenull
)ContextSingletonBeanFactoryLocator.getInstance()
protected java.lang.String getBeanFactoryLocatorKey(java.lang.Object target)
The default is null
, indicating the single
ApplicationContext defined in the locator. This must be overridden
if more than one shared ApplicationContext definition is available.
target
- the target bean to autowirenull
for
referring to the single ApplicationContext defined in the locator)@PreDestroy public void releaseBean(InvocationContext invocationContext)
invocationContext
- the EJB3 invocation contextprotected void doReleaseBean(java.lang.Object target)
target
- the target bean to release