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 虚拟机中的对象上的方法.可以用此方 ...
随机推荐
- Android:日常学习笔记(8)———探究UI开发(2)
Android:日常学习笔记(8)———探究UI开发(2) 对话框 说明: 对话框是提示用户作出决定或输入额外信息的小窗口. 对话框不会填充屏幕,通常用于需要用户采取行动才能继续执行的模式事件. 提示 ...
- Hexo 使用中搭建博客过程中遇到的坑
本地执行hexo s 时报错: WARN No layout: index.html 原因:theme 没有下载下来,经查,theme文件夹下为空. 新建文章后,执行 hexo g 时报如下错误: ( ...
- rails 下载 send_file
def download send_file File.join(Rails.root, "public", @doc.link), :filename => @title+ ...
- PHP 实现Session入库/存入redis
对于大访问量的站点使用默认的Session 并不合适,我们可以将其存入数据库.或者使用Redis KEY-VALUE数据存储方案 首先新建一个session表 CREATE TABLE `sessio ...
- Linux下32位与64位数据类型大小
Redhat Enterprise Linux 32 Redhat Enterprise Linux 64
- 【LeetCode】【矩阵旋转】Rotate Image
描述 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise ...
- 开发自己的composer package
参考:https://laravel-china.org/articles/6652/learn-to-develop-their-own-composer-package-and-to-use-pa ...
- uCOS-II的学习笔记(共九期)和例子(共六个)
源:uCOS-II的学习笔记(共九期)和例子(共六个) 第一篇 :学习UCOS前的准备工作http://blog.sina.com.cn/s/blog_98ee3a930100w0eu.html 第二 ...
- js怎么将光标移动特定的位置:
第一种方法: a 标签的锚: 将a标签的herf='#element_id_name' 即可 <a href="#comment_content" class=" ...
- 查看oracle当前连接数和进程数
查询数据库当前进程的连接数: select count(*) from v$process; 查看数据库当前会话的连接数: select count(*) from v$session; 查看数据库的 ...