public class SimpleRemoteSlsbInvokerInterceptor extends AbstractRemoteSlsbInvokerInterceptor implements DisposableBean
"Creates" a new EJB instance for each invocation, or caches the session
bean instance for all invocations (see setCacheSessionBean(boolean)
).
See JndiObjectLocator
for info on
how to specify the JNDI location of the target EJB.
In a bean container, this class is normally best used as a singleton. However, if that bean container pre-instantiates singletons (as do the XML ApplicationContext variants) you may have a problem if the bean container is loaded before the EJB container loads the target EJB. That is because by default the JNDI lookup will be performed in the init method of this class and cached, but the EJB will not have been bound at the target location yet. The best solution is to set the "lookupHomeOnStartup" property to "false", in which case the home will be fetched on first access to the EJB. (This flag is only true by default for backwards compatibility reasons).
This invoker is typically used with an RMI business interface, which serves as super-interface of the EJB component interface. Alternatively, this invoker can also proxy a remote SLSB with a matching non-RMI business interface, i.e. an interface that mirrors the EJB business methods but does not declare RemoteExceptions. In the latter case, RemoteExceptions thrown by the EJB stub will automatically get converted to Spring's unchecked RemoteAccessException.
RemoteAccessException
,
AbstractSlsbInvokerInterceptor.setLookupHomeOnStartup(boolean)
,
AbstractSlsbInvokerInterceptor.setCacheHome(boolean)
,
AbstractRemoteSlsbInvokerInterceptor.setRefreshHomeOnConnectFailure(boolean)
CONTAINER_PREFIX
logger
Constructor and Description |
---|
SimpleRemoteSlsbInvokerInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Remove the cached session bean instance, if necessary.
|
protected java.lang.Object |
doInvoke(MethodInvocation invocation)
This implementation "creates" a new EJB instance for each invocation.
|
protected java.lang.Object |
getSessionBeanInstance()
Return an EJB component instance to delegate the call to.
|
protected void |
refreshHome()
Reset the cached session bean instance, if necessary.
|
protected void |
releaseSessionBeanInstance(EJBObject ejb)
Release the given EJB instance.
|
void |
setCacheSessionBean(boolean cacheSessionBean)
Set whether to cache the actual session bean object.
|
getCreateMethod, invokeInContext, isConnectFailure, isHomeRefreshable, newSessionBeanInstance, refreshAndRetry, removeSessionBeanInstance, setRefreshHomeOnConnectFailure
afterPropertiesSet, create, getHome, invoke, setCacheHome, setExposeAccessContext, setLookupHomeOnStartup
getExpectedType, getJndiName, lookup, setExpectedType, setJndiName
convertJndiName, isResourceRef, lookup, lookup, setResourceRef
getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate
public void setCacheSessionBean(boolean cacheSessionBean)
Off by default for standard EJB compliance. Turn this flag on to optimize session bean access for servers that are known to allow for caching the actual session bean object.
@Nullable protected java.lang.Object doInvoke(MethodInvocation invocation) throws java.lang.Throwable
Alternatively, override getSessionBeanInstance()
and
releaseSessionBeanInstance(javax.ejb.EJBObject)
to change EJB instance creation,
for example to hold a single shared EJB component instance.
doInvoke
in class AbstractRemoteSlsbInvokerInterceptor
invocation
- the AOP method invocationjava.lang.Throwable
- in case of invocation failureAbstractSlsbInvokerInterceptor.getHome()
,
AbstractRemoteSlsbInvokerInterceptor.newSessionBeanInstance()
protected java.lang.Object getSessionBeanInstance() throws javax.naming.NamingException, java.lang.reflect.InvocationTargetException
The default implementation delegates to AbstractRemoteSlsbInvokerInterceptor.newSessionBeanInstance()
.
javax.naming.NamingException
- if thrown by JNDIjava.lang.reflect.InvocationTargetException
- if thrown by the create methodAbstractRemoteSlsbInvokerInterceptor.newSessionBeanInstance()
protected void releaseSessionBeanInstance(EJBObject ejb)
The default implementation delegates to AbstractRemoteSlsbInvokerInterceptor.removeSessionBeanInstance(javax.ejb.EJBObject)
.
ejb
- the EJB component instance to releaseAbstractRemoteSlsbInvokerInterceptor.removeSessionBeanInstance(javax.ejb.EJBObject)
protected void refreshHome() throws javax.naming.NamingException
refreshHome
in class AbstractSlsbInvokerInterceptor
javax.naming.NamingException
- if thrown by the JNDI lookupJndiObjectLocator.lookup()
,
AbstractSlsbInvokerInterceptor.getCreateMethod(java.lang.Object)
public void destroy()
destroy
in interface DisposableBean