public class JndiRmiServiceExporter extends RmiBasedExporter implements InitializingBean, DisposableBean
Exports services via the PortableRemoteObject
class.
You need to run "rmic" with the "-iiop" option to generate corresponding
stubs and skeletons for each exported service.
Also supports exposing any non-RMI service via RMI invokers, to be accessed
via JndiRmiClientInterceptor
/ JndiRmiProxyFactoryBean
's
automatic detection of such invokers.
With an RMI invoker, RMI communication works on the RmiInvocationHandler
level, needing only one stub for any service. Service interfaces do not have to
extend java.rmi.Remote
or throw java.rmi.RemoteException
on all methods, but in and out parameters have to be serializable.
The JNDI environment can be specified as "jndiEnvironment" bean property,
or be configured in a jndi.properties
file or as system properties.
For example:
<property name="jndiEnvironment"> <props> <prop key="java.naming.factory.initial">com.sun.jndi.cosnaming.CNCtxFactory</prop> <prop key="java.naming.provider.url">iiop://localhost:1050</prop> </props> </property>
RemoteExporter.setService(java.lang.Object)
,
setJndiTemplate(org.springframework.jndi.JndiTemplate)
,
setJndiEnvironment(java.util.Properties)
,
setJndiName(java.lang.String)
,
JndiRmiClientInterceptor
,
JndiRmiProxyFactoryBean
,
PortableRemoteObject.exportObject(java.rmi.Remote)
logger
Constructor and Description |
---|
JndiRmiServiceExporter() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware , ApplicationContextAware etc. |
void |
destroy()
Unbind the RMI service from JNDI on bean factory shutdown.
|
void |
prepare()
Initialize this service exporter, binding the specified service to JNDI.
|
void |
rebind()
Rebind the specified service to JNDI, for recovering in case
of the target registry having been restarted.
|
void |
setJndiEnvironment(java.util.Properties jndiEnvironment)
Set the JNDI environment to use for JNDI lookups.
|
void |
setJndiName(java.lang.String jndiName)
Set the JNDI name of the exported RMI service.
|
void |
setJndiTemplate(JndiTemplate jndiTemplate)
Set the JNDI template to use for JNDI lookups.
|
getObjectToExport, invoke
getRemoteInvocationExecutor, invokeAndCreateResult, setRemoteInvocationExecutor
checkService, checkServiceInterface, getExporterName, getProxyForService, getService, getServiceInterface, setInterceptors, setRegisterTraceInterceptor, setService, setServiceInterface
getBeanClassLoader, overrideThreadContextClassLoader, resetThreadContextClassLoader, setBeanClassLoader
public void setJndiTemplate(JndiTemplate jndiTemplate)
setJndiEnvironment(java.util.Properties)
public void setJndiEnvironment(java.util.Properties jndiEnvironment)
public void setJndiName(java.lang.String jndiName)
public void afterPropertiesSet() throws javax.naming.NamingException, java.rmi.RemoteException
InitializingBean
BeanFactory
after it has set all bean properties
and satisfied BeanFactoryAware
, ApplicationContextAware
etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
afterPropertiesSet
in interface InitializingBean
javax.naming.NamingException
java.rmi.RemoteException
public void prepare() throws javax.naming.NamingException, java.rmi.RemoteException
javax.naming.NamingException
- if service binding failedjava.rmi.RemoteException
- if service export failedpublic void rebind() throws javax.naming.NamingException
javax.naming.NamingException
- if service binding failedpublic void destroy() throws javax.naming.NamingException, java.rmi.NoSuchObjectException
destroy
in interface DisposableBean
javax.naming.NamingException
java.rmi.NoSuchObjectException