I implemented RMIService using Spring RMIServiceExporter running at port 4099. When I start my Jboss , RMI Service is getting bonded to 0.0.0.0:4099 instead of 127.0.0.1:4099. I tried different parameters
-Djava.rmi.server.hostname=127.0.0.1
-Djava.rmi.server.hostname=localhost
-Djava.rmi.server.hostname=localhost.localdomain along with
-Djava.net.preferIPv4Stack=true parameter.
Started Jboss with -b 127.0.0.1
Its always getting bonded to 0.0.0.0:4099. I check it using
>netstat -anp | grep 4099
>TCP 0.0.0.0:4099 0.0.0.0:0 LISTENING
Here is my implementation:
RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
rmiServiceExporter.setService(this);
rmiServiceExporter.setServiceName("MyService");
rmiServiceExporter.setServiceInterface(MyServiceManager.class);
rmiServiceExporter.setRegistryPort(4099);
rmiServiceExporter.afterPropertiesSet();
解决方案
java.rmi.server.hostname has nothing to do with setting the bind-address, and I'm not sure it has anything to do with Spring RMI either. It is a feature of the java.rmi package.
The listening port shown in the netstat output is the Registry port, not necessarily the port your server is listening on.
It appears you will have to define your own RMIServerSocketFactory that creates ServerSockets bound as you wish.