public class

SpringBeanAutowiringInterceptor

extends Object
java.lang.Object
   ↳ org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor

Class Overview

EJB3-compliant interceptor class that injects Spring beans into fields and methods which are annotated with @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(AutowiredAnnotationBeanPostProcessor, Object) template method.

The actual BeanFactory to obtain Spring beans from is determined by the getBeanFactory(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(Object) method and provide a specific locator key for each autowired EJB. Alternatively, override the getBeanFactory(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.

Summary

Public Constructors
SpringBeanAutowiringInterceptor()
Public Methods
void autowireBean(InvocationContext invocationContext)
Autowire the target bean after construction as well as after passivation.
void releaseBean(InvocationContext invocationContext)
Release the factory which has been used for autowiring the target bean.
Protected Methods
void configureBeanPostProcessor(AutowiredAnnotationBeanPostProcessor processor, Object target)
Template method for configuring the AutowiredAnnotationBeanPostProcessor used for autowiring.
void doAutowireBean(Object target)
Actually autowire the target bean after construction/passivation.
void doReleaseBean(Object target)
Actually release the BeanFactoryReference for the given target bean.
BeanFactory getBeanFactory(Object target)
Determine the BeanFactory for autowiring the given target bean.
BeanFactoryLocator getBeanFactoryLocator(Object target)
Determine the BeanFactoryLocator to obtain the BeanFactoryReference from.
String getBeanFactoryLocatorKey(Object target)
Determine the BeanFactoryLocator key to use.
BeanFactoryReference getBeanFactoryReference(Object target)
Determine the BeanFactoryReference for the given target bean.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public SpringBeanAutowiringInterceptor ()

Public Methods

public void autowireBean (InvocationContext invocationContext)

Autowire the target bean after construction as well as after passivation.

Parameters
invocationContext the EJB3 invocation context

public void releaseBean (InvocationContext invocationContext)

Release the factory which has been used for autowiring the target bean.

Parameters
invocationContext the EJB3 invocation context

Protected Methods

protected void configureBeanPostProcessor (AutowiredAnnotationBeanPostProcessor processor, Object target)

Template method for configuring the AutowiredAnnotationBeanPostProcessor used for autowiring.

Parameters
processor the AutowiredAnnotationBeanPostProcessor to configure
target the target bean to autowire with this processor

protected void doAutowireBean (Object target)

Actually autowire the target bean after construction/passivation.

Parameters
target the target bean to autowire

protected void doReleaseBean (Object target)

Actually release the BeanFactoryReference for the given target bean.

Parameters
target the target bean to release

protected BeanFactory getBeanFactory (Object target)

Determine the BeanFactory for autowiring the given target bean.

Parameters
target the target bean to autowire
Returns
  • the BeanFactory to use (never null)

protected BeanFactoryLocator getBeanFactoryLocator (Object target)

Determine the BeanFactoryLocator to obtain the BeanFactoryReference from.

The default implementation exposes Spring's default ContextSingletonBeanFactoryLocator.

Parameters
target the target bean to autowire
Returns
  • the BeanFactoryLocator to use (never null)
See Also

protected String getBeanFactoryLocatorKey (Object target)

Determine the BeanFactoryLocator key to use. This typically indicates the bean name of the ApplicationContext definition in classpath*:beanRefContext.xml resource files.

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.

Parameters
target the target bean to autowire
Returns
  • the BeanFactoryLocator key to use (or null for referring to the single ApplicationContext defined in the locator)

protected BeanFactoryReference getBeanFactoryReference (Object target)

Determine the BeanFactoryReference for the given target bean.

The default implementation delegates to getBeanFactoryLocator(Object) and getBeanFactoryLocatorKey(Object).

Parameters
target the target bean to autowire
Returns
  • the BeanFactoryReference to use (never null)