Spring Remoting: Remote Method Invocation (RMI)
2015-11-23 15:04
465 查看
http://www.studytrails.com/frameworks/spring/spring-remoting-rmi.jsp
http://shouce.jb51.net/spring/remoting.html http://www.javaworld.com/article/2072246/simple-spring-http-remoting-example.html
Required Libraries
Server 端:springremotingrmiserver
spring-config-server.xml:
Client 端:springremotingrmiclient
spring-config-client.xml:
先启动Server, 后运行Client, 输出:
目录结构:
http://shouce.jb51.net/spring/remoting.html http://www.javaworld.com/article/2072246/simple-spring-http-remoting-example.html
Required Libraries
aopalliance.jar commons-logging.jar log4j.jar org.springframework.aop.jar org.springframework.asm.jar org.springframework.beans.jar org.springframework.context.jar org.springframework.context.support.jar org.springframework.core.jar org.springframework.expression.jar
Server 端:springremotingrmiserver
package com.studytrails.tutorials.springremotingrmiserver; public interface GreetingService { String getGreeting(String name); }
package com.studytrails.tutorials.springremotingrmiserver; public interface GreetingService { String getGreeting(String name); }
package com.studytrails.tutorials.springremotingrmiserver; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class StartRmiServer { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-server.xml"); System.out.println("Waiting for Request from Client ..."); } }
spring-config-server.xml:
<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean id="greetingService" class="com.studytrails.tutorials.springremotingrmiserver.GreetingServiceImpl" /> <bean class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="serviceName" value="greetingService" /> <property name="service" ref="greetingService" /> <property name="serviceInterface" value="com.studytrails.tutorials.springremotingrmiserver.GreetingService"/> <property name="registryPort" value="1099" /> </bean> </beans>
Client 端:springremotingrmiclient
package com.studytrails.tutorials.springremotingrmiserver; //和server的一样 public interface GreetingService { String getGreeting(String name); }
package com.studytrails.tutorials.springremotingrmiclient; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.studytrails.tutorials.springremotingrmiserver.GreetingService; public class TestSpringRemotingRmi { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-client.xml"); GreetingService greetingService = (GreetingService)context.getBean("greetingService"); String greetingMessage = greetingService.getGreeting("Alpha"); System.out.println("The greeting message is : " + greetingMessage); } }
spring-config-client.xml:
<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean id="greetingService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://localhost:1099/greetingService"/> <property name="serviceInterface" value="com.studytrails.tutorials.springremotingrmiserver.GreetingService"/> </bean> </beans>
先启动Server, 后运行Client, 输出:
The greeting message is : Hello Alpha!
目录结构:
相关文章推荐
- Spring中Quartz的配置
- 配置jdk
- Eclipse 优化方法(经典收藏)
- eclipse设置护眼豆沙绿背景色以及字体颜色
- 多图详解Spring框架的设计理念与设计模式
- java中的System.nanoTime与System.currentTime
- ubuntu下安装jre,Eclipse, CDT
- java.io.IOException: error=24, 打开的文件过多
- Java贪吃蛇的简单实现
- eclipse ---修改新建jsp模板
- JAVA 正则表达式 (超详细)
- 【转】The import javax.servlet cannot be resolved
- java环境变量配置问题
- The import java.io cannot be resolved
- java读取ipa、apk文件中的配置信息
- java split
- 关于多个的线程操作文件 文件句柄(java中得文件流)
- Java环境变量的配置
- Java环境变量的配置
- Java环境变量的配置