15.2使用RMI
阿新 • • 發佈:2021-01-21
15.2.1匯出RMI服務
RmiServiceExporter可以把任意Spring管理的bean釋出到RMI服務。package spittr.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.rmi.RmiServiceExporter;
import spittr.service.SpitterService;
/**
* @version版權 Copyright(c)2019
* @ClassName:
* @Descripton: 匯出RMI
* @author: Shing
* @date: 2020-07-17 15:28
*/
@Configuration
public class RpcConfig {
/**
* RmiServiceExporter可以將任意sping管理的bean釋出到RMI服務。
* @param spitterService
* @return
*/
@Bean
public RmiServiceExporter rmiServiceExporter(SpitterService spitterService){
RmiServiceExporter rmiServiceExporter = newRmiServiceExporter();
rmiServiceExporter.setService(spitterService);
rmiServiceExporter.setServiceName("SpitterService");
rmiServiceExporter.setServiceInterface(SpitterService.class);
//預設情況下,rmiServiceExporter會嘗試繫結到本機1099埠上的RMI登錄檔。
//如果在這個埠沒有發現RMI登錄檔,rmiServiceExporter將會啟動一個登錄檔rmiServiceExporter.setRegistryHost("rmi.spittr.com");
rmiServiceExporter.setRegistryPort(1199);
return rmiServiceExporter;
}
}
15.2.1裝配RMI服務
@Bean
public RmiProxyFactoryBean rmiProxyFactoryBean(){
RmiProxyFactoryBean rmiProxy = new RmiProxyFactoryBean();
rmiProxy.setServiceUrl("rmi://localhost/SpitterService");
rmiProxy.setServiceInterface(SpitterService.class);
return rmiProxy;
}
來自為知筆記(Wiz)