孙鑫mfc学习笔记第七八课
2010-08-24 23:14
387 查看
刚刚学习了RMI基础运用,现在来看一下 spring对RMI的支持。
这边要注意一点,和普通的RMI相比,和spring结合不再继承 UnicastRemoteObject
接口变成
而不是之前的
其他的配置不变,现在看看spring配置文件
服务端:applicationContext.xml
客户端:applicationContext2.xml
就是那么简单。
测试一下:
这边要注意一点,和普通的RMI相比,和spring结合不再继承 UnicastRemoteObject
接口变成
public class StudentMsg implements IStudentMsg
而不是之前的
public class StudentMsg extends UnicastRemoteObject implements IStudentMsg
其他的配置不变,现在看看spring配置文件
服务端:applicationContext.xml
<!--服务端--> <bean id="studentServiceImpl" class="com.Rmi.Serv.StudentMsg" scope="prototype"/> <!-- 将类为一个RMI服务 --> <bean id="studentService" class="org.springframework.remoting.rmi.RmiServiceExporter"> <!-- 服务类 --> <property name="service" ref="studentServiceImpl" /> <!-- 服务名 --> <property name="serviceName" value="studentServices" /> <!-- 服务接口 --> <property name="serviceInterface" value="com.Rmi.Imp.IStudentMsg" /> <!-- 服务端口 --> <property name="registryPort" value="9999" /> </bean>
客户端:applicationContext2.xml
<!--客户端--> <bean id="myClient" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://127.0.0.1:9999/studentServices"/> <property name="serviceInterface" value="com.Rmi.Imp.IStudentMsg"/> </bean>
就是那么简单。
测试一下:
客户端: public class ClientTest { public static void main(String[] args) throws RemoteException { plicationContext context = new ClassPathXmlApplicationContext("applicationContext2.xml"); tudentMsg hms = context.getBean("myClient", IStudentMsg.class); System.out.println(hms.findStudentArray().length); }
public class ServerTest {
public static void main(String[] args) { //初始化工作只能运行一次;运行多次的话,会启动多个服务 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); } }
相关文章推荐
- 孙鑫VC学习笔记:第八讲 逃跑按钮的巧妙实现和MFC中指针的获取
- 孙鑫mfc学习笔记第六课
- [MFC学习笔记]--孙鑫第三课
- 孙鑫mfc学习笔记第十五课
- 孙鑫mfc学习笔记第九课
- MFC孙鑫视频学习笔记
- 孙鑫mfc学习笔记第十课
- 孙鑫mfc学习笔记第十一课
- 孙鑫VC学习笔记:第十五讲 编写一个基于MFC对话框的聊天程序
- 孙鑫VC学习笔记:第十五讲 编写一个基于MFC对话框的聊天程序
- 孙鑫mfc学习笔记第十二课
- 孙鑫VC++视频学习笔记之2: MFC程序框架的剖析
- 孙鑫VC学习笔记:第八讲 逃跑按钮的巧妙实现和MFC中指针的获取
- 孙鑫mfc学习笔记第十三课
- 孙鑫VC++视频学习笔记之3: MFC消息映射机制和绘图DC
- 孙鑫mfc学习笔记第十四课
- 孙鑫mfc学习笔记第十五课
- 孙鑫mfc学习笔记第十六课
- 孙鑫mfc学习笔记第十七课
- 孙鑫VC学习笔记:第十五讲 (四) 编写一个基于MFC对话框的聊天程序