diff --git a/src/main/Resources/sys_config.properties b/src/main/Resources/sys_config.properties index acab0bc..1f7bd0f 100644 --- a/src/main/Resources/sys_config.properties +++ b/src/main/Resources/sys_config.properties @@ -34,4 +34,7 @@ mail.freemarker.template=/email_template/ #第三方平台推送开关 true打开 false关闭 task.push.switch=false #第三方平台推送URL -task.push.url=localhost \ No newline at end of file +task.push.url=localhost +#==================================RMI接口指定本地IP============================================ +#当客户端存在多个网卡(如:虚拟机的网卡),那么客户端就存在多个IP,此时必须指定一个实际IP地址注册RMI服务,如果只有一个网卡,可默认localhost +client.localhost.ip=localhost \ No newline at end of file diff --git a/src/main/java/rmi/remotingservice/Program.java b/src/main/java/rmi/remotingservice/Program.java index b378181..ac1bf10 100644 --- a/src/main/java/rmi/remotingservice/Program.java +++ b/src/main/java/rmi/remotingservice/Program.java @@ -2,6 +2,7 @@ package rmi.remotingservice; import java.rmi.Naming; import java.rmi.registry.LocateRegistry; +import java.util.Properties; import rmi.service.RunService; import rmi.serviceimpl.RunServiceImpl; @@ -22,12 +23,17 @@ public class Program{ public static void main(String[] args) { // TODO Auto-generated method stub try { + Properties properties= luckyclient.publicclass.SysConfig.getConfiguration(); + String localhostip=properties.getProperty("client.localhost.ip"); + if(!"localhost".toLowerCase().equals(localhostip)){ + System.setProperty("java.rmi.server.hostname", localhostip); + } RunService runService=new RunServiceImpl(); //注册通讯端口 LocateRegistry.createRegistry(6633); //注册通讯路径 - Naming.rebind("rmi://localhost:6633/RunService", runService); - System.out.println("启动客户端监听...端口:6633"); + Naming.rebind("rmi://"+localhostip+":6633/RunService", runService); + System.out.println("启动客户端监听...IP:"+localhostip+" 端口:6633"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace();