Spring框架实现——远程方法调用RMI代码演示
1、spring_RMI02_server服务端02
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 扫描包基础目录 -->
<context:component-scan base-package="com.wisezone"></context:component-scan> 20 <!-- 配置RMI -->
21 <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
22 <property name="serviceName" value="hello"></property>
23 <property name="service" ref="helloServiceImpl"></property>
24 <property name="serviceInterface" value="com.wisezone.service.IHelloService"></property>
25 <property name="registryPort" value="1199"></property>
26 </bean>
</beans>
package com.wisezone.service;
public interface IHelloService {
public String sayHello(String msg);
}
package com.wisezone.service.impl; import org.springframework.stereotype.Service; import com.wisezone.service.IHelloService; @Service
public class HelloServiceImpl implements IHelloService { @Override
public String sayHello(String msg) { System.out.println("服务端接受消息:"+msg);
return "hello-->>"+msg;
} }
package com.wisezone.test; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Publish { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
}
}
2、spring_RMI02_client客户端02
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 扫描包基础目录 -->
<context:component-scan base-package="com.wisezone"></context:component-scan> 20 <bean class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
21 <property name="serviceUrl" value="rmi://localhost:1199/hello"></property>
22 <property name="serviceInterface" value="com.wisezone.service.IHelloService"></property>
23 </bean> </beans>
package com.wisezone.service;
public interface IHelloService {
public String sayHello(String msg);
}
package com.wisezone.impl; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.wisezone.service.IHelloService; @Service
public class UserServiceImpl { @Resource
private IHelloService helloService; public void test(){
System.out.println("客户端发送消息:"+helloService.sayHello("im window7SP1旗舰版"));
} }
package com.wisezone.test; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wisezone.impl.UserServiceImpl; public class Test {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
UserServiceImpl userServiceImpl = (UserServiceImpl) ac.getBean("userServiceImpl");
userServiceImpl.test();
}
}
发布顺序:先发布服务端,再发布客户端
结果:


Spring框架实现——远程方法调用RMI代码演示的更多相关文章
- 普通方法实现——远程方法调用RMI代码演示
1.spring_RMI01_server服务端 package com.wisezone.service; import java.rmi.Remote; import java.rmi.Remot ...
- 【Java Web开发学习】远程方法调用RMI
Java RMI 远程方法调用Remote Method Invocation 转载:http://www.cnblogs.com/yangchongxing/p/9078061.html 1.创建远 ...
- SpringBoot里使用RMI进行远程方法调用
一.Java RMI定义 Java RMI:Java远程方法调用,即Java RMI(Java Remote Method Invocation)是Java编程语言里,一种用于实现远程过程调用的应用程 ...
- RMI远程方法调用
RMI远程方法调用:适用于 客户端 调用 服务器 内的方法:(Kotlin 语言编写) 如果业务为二个服务器之间的通信,还是得用消息队列的形式,因为RMI 不适合 双向 调用 下面介绍RMI 的使用方 ...
- Java APi 之 RMI远程方法调用
一.什么是RPC RPC全称是remote procedure call,即远程过程调用.它是一种协议,用于从远程计算机上请求服务. 例如有两台服务器A和B,A上的应用想要调用B上应用的方法,但是他们 ...
- 简单实现Java的RMI——远程方法调用
一.RMI简介: 说到RMI就不得不说RPC了. RPC:(Remote Procedure Call),远程过程调用. RMI(Remote Method Invocation),远程方法调用. R ...
- [转]Java远程方法调用
Java远程方法调用,即Java RMI(Java Remote Method Invocation)是Java编程语言里,一种用于实现远程过程调用的应用程序编程接口.它使客户机上运行的程序可以调用远 ...
- XML-RPC远程方法调用
一.简介 XML-RPC的全称是XML Remote Procedure Call,即XML远程方法调用. 它是一套允许运行在不同操作系统.不同环境的程序实现基于Internet过程调用的规范和一系列 ...
- Java RMI 远程方法调用
Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可以用此方 ...
随机推荐
- LCA(最近公共祖先)专题(不定期更新)
Tarjan(离线)算法 思路: 1.任选一个点为根节点,从根节点开始. 2.遍历该点u所有子节点v,并标记这些子节点v已被访问过. 3.若是v还有子节点,返回2,否则下一步. 4.合并v到u上. 5 ...
- java eclipse 监视选择指定变量
http://3y.uu456.com/bp_8tzmk3zobb7k6x46aj28_1.html 有时一个Java程序有许多变量,但你仅对其中一个或几个感兴趣,为了监视选择的变量和表达式,你可以将 ...
- LeetCode:数据库技术【175-178】
LeetCode:数据库技术[175-178] LeetCode已经刷完200道题目,但这只是开始,下一段时间,仍然把刷题作为重点,争取再次完成200道,本篇博客将会带大家熟悉一些数据库面试题,从简单 ...
- JQuery 获取父元素方法
---恢复内容开始--- <tr class="removerow" style=""> <td> <input type=&qu ...
- Nginx负载均衡案例
nginx负载均衡配置,windows版本和linux版本的nginx除了启动方式其他基本无差异. 1.Niginx安装 参考:https://www.cnblogs.com/zwcry/p/9454 ...
- linux环境vim升级到vim74
作为编辑器之神,vim7.4已经发布近两个月了.从vim7.3到vim7.4,时隔两年之久,做了多项改正和性能提升,作为Linux Geeksters的你,怎能错过. 由于各大主流linux操作系统都 ...
- 20145240 《Java程序设计》第三次实验报告
20145240 <Java程序设计>第三次实验报告 北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1452 指导教师:娄嘉鹏 实验日期:2016.04.22 实验 ...
- 《深度学习框架PyTorch:入门与实践》的Loss函数构建代码运行问题
在学习陈云的教程<深度学习框架PyTorch:入门与实践>的损失函数构建时代码如下: 可我运行如下代码: output = net(input) target = Variable(t.a ...
- Docker 配置代理
最近在k8s上部署helm 老提示无法下载镜像,因为伟大的祖国的长城Firewall....导致k8s根本玩不了..... 第一步:配置系统代理 # vim .bashrc export http_p ...
- 【atcoder】Two Sequences [arc092 D](思维题)
题目传送门:https://arc092.contest.atcoder.jp/tasks/arc092_b 这场arc好难啊...这场感觉不像正常的arc...其实这道题还可以更早写出来的,但是蒟蒻 ...