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代码演示的更多相关文章

  1. 普通方法实现——远程方法调用RMI代码演示

    1.spring_RMI01_server服务端 package com.wisezone.service; import java.rmi.Remote; import java.rmi.Remot ...

  2. 【Java Web开发学习】远程方法调用RMI

    Java RMI 远程方法调用Remote Method Invocation 转载:http://www.cnblogs.com/yangchongxing/p/9078061.html 1.创建远 ...

  3. SpringBoot里使用RMI进行远程方法调用

    一.Java RMI定义 Java RMI:Java远程方法调用,即Java RMI(Java Remote Method Invocation)是Java编程语言里,一种用于实现远程过程调用的应用程 ...

  4. RMI远程方法调用

    RMI远程方法调用:适用于 客户端 调用 服务器 内的方法:(Kotlin 语言编写) 如果业务为二个服务器之间的通信,还是得用消息队列的形式,因为RMI 不适合 双向 调用 下面介绍RMI 的使用方 ...

  5. Java APi 之 RMI远程方法调用

    一.什么是RPC RPC全称是remote procedure call,即远程过程调用.它是一种协议,用于从远程计算机上请求服务. 例如有两台服务器A和B,A上的应用想要调用B上应用的方法,但是他们 ...

  6. 简单实现Java的RMI——远程方法调用

    一.RMI简介: 说到RMI就不得不说RPC了. RPC:(Remote Procedure Call),远程过程调用. RMI(Remote Method Invocation),远程方法调用. R ...

  7. [转]Java远程方法调用

    Java远程方法调用,即Java RMI(Java Remote Method Invocation)是Java编程语言里,一种用于实现远程过程调用的应用程序编程接口.它使客户机上运行的程序可以调用远 ...

  8. XML-RPC远程方法调用

    一.简介 XML-RPC的全称是XML Remote Procedure Call,即XML远程方法调用. 它是一套允许运行在不同操作系统.不同环境的程序实现基于Internet过程调用的规范和一系列 ...

  9. Java RMI 远程方法调用

    Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可以用此方 ...

随机推荐

  1. 系统非正常关机启动后出现:an error occurred during the file system

    现象描述: 1.系统ssh登录报Too many open files in system,系统登录不进去,就直接强制关机了,开机后出现(2)的错误: 由于文件描述符用完了,需要把fs.file-ma ...

  2. php......留言板

    部门内部留言板 一.语言和环境 实现语言 PHP 二.要求: 本软件是作为部门内员工之间留言及发送消息使用. 系统必须通过口令验证,登录进入.方法是从数据库内取出用户姓名和口令的数据进行校验. 用户管 ...

  3. $Android AlarmManager的用法详解

    在Android的Alarm机制中,使用AlarmManager可以实现类似闹钟这样的定时任务.在毕业设计项目中要实现定时任务的功能,所以在这里先进行一下梳理. (一)AlarmManager与Bro ...

  4. React routerV4 笔记

    React routerV4 笔记     一.基础路由示例 import React from 'react' import { BrowserRouter as Router, Route, Li ...

  5. 查看oracle当前连接数和进程数

    查询数据库当前进程的连接数: select count(*) from v$process; 查看数据库当前会话的连接数: select count(*) from v$session; 查看数据库的 ...

  6. 主攻ASP.NET.4.5.1 MVC5.0之重生:根据产品类别显示菜单分类和分页

    路径访问的几种方式和分页效果 显示其它类别的效果和多数据分页效果 默认访问网站路径效果和多数据分页效果 URL路径访问可页面 http://localhost:5339/stationery http ...

  7. linux下安装jsp开发运行环境(centos7)

    1 开发环境包括 1)apache-tomcat 2)java-jdk 3)mysql 2 apache-tomcat安装(应该先装java再装tomcat) 1)到官网下载最新版本(不建议用yum安 ...

  8. .NET自带泛型委托方法Func、Action和Predicate

    Func.Action和Predicate是.NET自带的3个泛型委托方法,三个方法的区别其实并不大,要强行给混着用也是可以的,但是我们是有追求的人,把道理讲清楚总是好的. 一.Func是有返回值的方 ...

  9. 斯坦福机器学习视频笔记 Week7 支持向量机 Support Vector Machines

    SVM被许多人认为是最强大的“黑箱”学习算法,并通过提出一个巧妙选择的优化目标,今天最广泛使用的学习算法之一. Optimization Objective 根据Logistic Regression ...

  10. Python 数值类型

    1.数值类型分为整形(二进制(0b),八进制(0o),十进制,十六进制(0x) ),浮点型,long,complex(复合行) 当我们说十进制数的时候,是逢10进1,就是说到达10的时候就要向前一位进 ...