一:服务端开发: <bean id="webImagesServiceImpl" class="com.yknet.llgo.service.rmi.impl.WebImagesServiceImpl" ></bean> <!-- 图片管理服务接口 --> <bean id="webImagesServiceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter"> <!-- 服务的实现类 --> <property name="service" ref="webImagesServiceImpl" /> <!-- 定义服务名,给客户端调用的名称 --> <property name="serviceName" value="webImagesService" /> <!-- 服务端的接口 --> <property name="serviceInterface" value="com.yknet.llgo.service.rmi.IWebImagesService" /> <!-- 服务端的端口号,这个也是供客户端调用的 --> <property name="registryPort" value="8088"></property> <property name="servicePort" value="2098"/><!--不指定就随机 --> </bean> <bean id="sMRMISocket" class="com.yknet.llgo.core.SMRMISocket"></bean>
//解决外网访问时连接超时package com.yknet.llgo.core; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.rmi.server.RMISocketFactory; public class SMRMISocket extends RMISocketFactory { public Socket createSocket(String host, int port) throws IOException{ return new Socket(host,port); } public ServerSocket createServerSocket(int port) throws IOException { if (port == 0) port = 2098;//不指定就随机 return new ServerSocket(port); } }
二:客服端配置:
<bean id="imagesServiceWeb" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <!-- 端口号必须和服务端配置的要一模一样 8088/imagesServiceWeb:就是服务端配置的 serviceName --> <property name="serviceUrl" value="rmi://121.42.138.7:8088/webImagesService"></property> <!-- 服务端的接口 --> <property name="serviceInterface" value="com.yknet.llgo.service.rmi.IWebImagesService" /> </bean>
时间: 2024-10-29 10:46:23