<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="1099"/>
</bean>
<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFactoryBean"
depends-on="registry">
<property name="objectName" value="connector:name=rmi"/>
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/jmxrmi"/>
</bean>
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="host" value="localhost" />
<property name="port" value="1099"/>
</bean>
<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFactoryBean"
depends-on="registry">
<property name="objectName" value="connector:name=rmi"/>
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/jmxrmi"/>
</bean>
At first glance, it would seem simple to assume, because localhost is the default setting for RMI registry host exposed by Spring, that these two XML snippets would result in the same functionality for the Spring-based application. However, there is a significant difference caused by the presence or lack of this one line.
In the first case (no host specified), Spring will start an RMI registry if it cannot find one. That RMI registry will be started on the localhost.
At this point, it is natural to assume that the second listing will lead to the same result because localhost is explicitly specified as the host. However, this is not the case. When localhost is explicitly specified as a host, the RMI registry must be started externally first (for example, by running rmiregistry) and then Spring will use that running RMI registry. If one specifies localhost explicitly and has not previously started an RMI registry on that host and port, an exception will be encountered that includes this line: java.rmi.ConnectException: Connection refused to host: localhost.
This is the case for RmiRegistryFactoryBean as used in the examples above, but the same thing is just as true for using RmiServiceExporter for RMI remoting. The only difference is that RmiServiceExporter has registryHost rather than host for the attribute that affects whether an RMI registry needs to be running before the Spring container is started.
Không có nhận xét nào:
Đăng nhận xét