日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring远程支持和开发RMI服务

發(fā)布時(shí)間:2023/12/3 javascript 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring远程支持和开发RMI服务 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Spring遠(yuǎn)程支持簡化了啟用遠(yuǎn)程服務(wù)的開發(fā)。 當(dāng)前,Spring支持以下遠(yuǎn)程技術(shù):遠(yuǎn)程方法調(diào)用(RMI),HTTP調(diào)用程序,Hessian,Burlap,JAX-RPC,JAX-WS和JMS。

遠(yuǎn)程方法調(diào)用(RMI) :Spring通過RmiProxyFactoryBean和RmiServiceExporter支持RMI。 RmiServiceExporter將任何Spring管理的bean導(dǎo)出為RMI服務(wù)并進(jìn)行注冊(cè)。 RmiProxyFactoryBean是一種工廠bean,可為RMI服務(wù)創(chuàng)建代理。 該代理對(duì)象代表客戶端與遠(yuǎn)程RMI服務(wù)進(jìn)行通信。

Spring的HTTP調(diào)用程序: Spring HTTP調(diào)用程序使用標(biāo)準(zhǔn)的Java序列化機(jī)制通過HTTP公開服務(wù)。 Spring通過HttpInvokerProxyFactoryBean和HttpInvokerServiceExporter支持HTTP調(diào)用程序基礎(chǔ)結(jié)構(gòu)。 HttpInvokerServiceExporter,它將指定的服務(wù)bean導(dǎo)出為HTTP調(diào)用程序服務(wù)端點(diǎn),可通過HTTP調(diào)用程序代理訪問。 HttpInvokerProxyFactoryBean是用于HTTP調(diào)用程序代理的工廠bean。

Hessian: Hessian提供了一個(gè)基于HTTP的二進(jìn)制遠(yuǎn)程協(xié)議。 Spring通過HessianProxyFactoryBean和HessianServiceExporter支持Hessian。

粗麻布:粗麻布是Caucho的基于XML的粗麻布替代品。 Spring提供了支持類,例如BurlapProxyFactoryBean和BurlapServiceExporter。

JAX-RPC: Spring通過JAX-RPC(J2EE 1.4的Web服務(wù)API)為Web服務(wù)提供遠(yuǎn)程支持。

JAX-WS: Spring通過JAX-WS(Java EE 5和Java 6中引入的JAX-RPC的繼承者)為Web服務(wù)提供遠(yuǎn)程支持。

JMS: JmsInvokerServiceExporter和JmsInvokerProxyFactoryBean類提供了Spring中的JMS遠(yuǎn)程支持。

讓我們看一下Spring RMI支持以開發(fā)Spring RMI Service&Client。

二手技術(shù):

JDK 1.6.0_31
春天3.1.1
Maven的3.0.2

步驟1:建立已完成的專案

創(chuàng)建一個(gè)Maven項(xiàng)目,如下所示。 (可以使用Maven或IDE插件來創(chuàng)建它)。

步驟2:圖書館

Spring依賴項(xiàng)已添加到Maven的pom.xml中。

<!-- Spring 3.1.x dependencies --> <properties><spring.version>3.1.1.RELEASE</spring.version> </properties><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency> <dependencies>

步驟3:建立使用者類別

創(chuàng)建一個(gè)新的用戶類。

package com.otv.user;import java.io.Serializable;/*** User Bean** @author onlinetechvision.com* @since 24 Feb 2012* @version 1.0.0**/ public class User implements Serializable {private long id;private String name;private String surname;/*** Get User Id** @return long id*/public long getId() {return id;}/*** Set User Id** @param long id*/public void setId(long id) {this.id = id;}/*** Get User Name** @return long id*/public String getName() {return name;}/*** Set User Name** @param String name*/public void setName(String name) {this.name = name;}/*** Get User Surname** @return long id*/public String getSurname() {return surname;}/*** Set User Surname** @param String surname*/public void setSurname(String surname) {this.surname = surname;}@Overridepublic String toString() {StringBuilder strBuilder = new StringBuilder();strBuilder.append("Id : ").append(getId());strBuilder.append(", Name : ").append(getName());strBuilder.append(", Surname : ").append(getSurname());return strBuilder.toString();} }

步驟4:建立ICacheService介面

創(chuàng)建了代表遠(yuǎn)程緩存服務(wù)接口的ICacheService接口。

package com.otv.cache.service;import java.util.concurrent.ConcurrentHashMap;import com.otv.user.User;/*** Cache Service Interface** @author onlinetechvision.com* @since 27 Feb 2012* @version 1.0.0**/ public interface ICacheService {/*** Get User Map** @return ConcurrentHashMap User Map*/public ConcurrentHashMap<long, user> getUserMap();}

步驟5:創(chuàng)建CacheService類

CacheService類是通過實(shí)現(xiàn)ISchedulerService接口創(chuàng)建的。 它提供對(duì)遠(yuǎn)程緩存的訪問…

package com.otv.cache.service;import java.util.concurrent.ConcurrentHashMap;import com.otv.user.User;/*** Cache Service Implementation** @author onlinetechvision.com* @since 6:04:49 PM* @version 1.0.0**/ public class CacheService implements ICacheService {//User Map is injected...ConcurrentHashMap<long, user> userMap;/*** Get User Map** @return ConcurrentHashMap User Map*/public ConcurrentHashMap<long, user> getUserMap() {return userMap;}/*** Set User Map** @param ConcurrentHashMap User Map*/public void setUserMap(ConcurrentHashMap<long, user> userMap) {this.userMap = userMap;}}

步驟6:建立IRMIUserService接口

創(chuàng)建代表RMI服務(wù)接口的IRMIUserService接口。 另外,它為RMI客戶端提供了遠(yuǎn)程方法。

package com.otv.rmi.server;import java.util.List;import com.otv.user.User;/*** RMI User Service Interface** @author onlinetechvision.com* @since 24 Feb 2012* @version 1.0.0**/ public interface IRMIUserService {/*** Add User** @param User user* @return boolean response of the method*/public boolean addUser(User user);/*** Delete User** @param User user* @return boolean response of the method*/public boolean deleteUser(User user);/*** Get User List** @return List user list*/public List<User> getUserList();}

步驟7:創(chuàng)建RMIUserService類

RMIUserService類(又名RMI對(duì)象)是通過實(shí)現(xiàn)IRMIUserService接口創(chuàng)建的。

package com.otv.rmi.server;import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger;import com.otv.cache.service.ICacheService; import com.otv.user.User;/*** RMI User Service Implementation** @author onlinetechvision.com* @since 24 Feb 2012* @version 1.0.0**/ public class RMIUserService implements IRMIUserService {private static Logger logger = Logger.getLogger(RMIUserService.class);//Remote Cache Service is injected...ICacheService cacheService;/*** Add User** @param User user* @return boolean response of the method*/public boolean addUser(User user) {getCacheService().getUserMap().put(user.getId(), user);logger.debug("User has been added to cache. User : "+getCacheService().getUserMap().get(user.getId()));return true;}/*** Delete User** @param User user* @return boolean response of the method*/public boolean deleteUser(User user) {getCacheService().getUserMap().put(user.getId(), user);logger.debug("User has been deleted from cache. User : "+user);return true;}/*** Get User List** @return List user list*/public List<User> getUserList() {List<User> list = new ArrayList<User>();list.addAll(getCacheService().getUserMap().values());logger.debug("User List : "+list);return list;}/*** Get RMI User Service** @return IRMIUserService RMI User Service*/public ICacheService getCacheService() {return cacheService;}/*** Set RMI User Service** @param IRMIUserService RMI User Service*/public void setCacheService(ICacheService cacheService) {this.cacheService = cacheService;} }

步驟8:創(chuàng)建RMIServerStarter類別

RMI服務(wù)器啟動(dòng)程序類已創(chuàng)建。 它啟動(dòng)RMI服務(wù)器。

package com.otv.rmi.server.starter;import org.springframework.context.support.ClassPathXmlApplicationContext;/*** RMI Server Starter** @author onlinetechvision.com* @since 27 Feb 2012* @version 1.0.0**/ public class RMIServerStarter {public static void main(String[] args) {//RMI Server Application Context is started...new ClassPathXmlApplicationContext("rmiServerAppContext.xml");} }

步驟9:創(chuàng)建rmiServerAppContext.xml

RMI服務(wù)器應(yīng)用程序上下文的內(nèi)容如下所示。

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- Beans Declaration --><bean id="UserMap" class="java.util.concurrent.ConcurrentHashMap" /><bean id="CacheService" class="com.otv.cache.service.CacheService"><property name="userMap" ref="UserMap"/></bean> <bean id="RMIUserService" class="com.otv.rmi.server.RMIUserService" ><property name="cacheService" ref="CacheService"/></bean><!-- RMI Server Declaration --><bean class="org.springframework.remoting.rmi.RmiServiceExporter"><!-- serviceName represents RMI Service Name --><property name="serviceName" value="RMIUserService"/><!-- service represents RMI Object(RMI Service Impl) --><property name="service" ref="RMIUserService"/><!-- serviceInterface represents RMI Service Interface exposed --><property name="serviceInterface" value="com.otv.rmi.server.IRMIUserService"/><!-- defaults to 1099 --><property name="registryPort" value="1099"/></bean></beans>

步驟10:創(chuàng)建RMIServiceClient類

RMIServiceClient類已創(chuàng)建。 它調(diào)用RMI用戶服務(wù)并執(zhí)行用戶操作。

package com.otv.rmi.client;import org.apache.log4j.Logger; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import com.otv.rmi.server.IRMIUserService; import com.otv.rmi.server.RMIUserService; import com.otv.user.User;/*** RMI Service Client** @author onlinetechvision.com* @since 24 Feb 2012* @version 1.0.0**/ public class RMIServiceClient {private static Logger logger = Logger.getLogger(RMIUserService.class);/*** Main method of the RMI Service Client**/public static void main(String[] args) {logger.debug("RMI Service Client is starting...");//RMI Client Application Context is started...ApplicationContext context = new ClassPathXmlApplicationContext("rmiClientAppContext.xml");//Remote User Service is called via RMI Client Application Context...IRMIUserService rmiClient = (IRMIUserService) context.getBean("RMIUserService");//New User is created...User user = new User();user.setId(1);user.setName("Bruce");user.setSurname("Willis");//The user is added to the remote cache...rmiClient.addUser(user);//The users are gotten via remote cache...rmiClient.getUserList();//The user is deleted from remote cache...rmiClient.deleteUser(user);logger.debug("RMI Service Client is stopped...");} }

步驟11:創(chuàng)建rmiClientAppContext.xml

RMI客戶端應(yīng)用程序上下文的內(nèi)容如下所示。

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- RMI Client Declaration --><bean id="RMIUserService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"><!-- serviceUrl represents RMI Service Url called--><property name="serviceUrl" value="rmi://x.x.x.x:1099/RMIUserService"/><!-- serviceInterface represents RMI Service Interface called --><property name="serviceInterface" value="com.otv.rmi.server.IRMIUserService"/><!-- refreshStubOnConnectFailure enforces automatic re-lookup of the stub if acall fails with a connect exception --><property name="refreshStubOnConnectFailure" value="true"/></bean></beans>

步驟12:運(yùn)行項(xiàng)目

如果運(yùn)行RMI Server時(shí)啟動(dòng)了RMI Service Client,則將在RMI Server輸出日志下方顯示。 同樣,可以通過IDE打開兩個(gè)單獨(dú)的控制臺(tái)來運(yùn)行RMI Server和Client。 :

.... 04.03.2012 14:23:15 DEBUG (RmiBasedExporter.java:59) - RMI service [com.otv.rmi.server.RMIUserService@16dadf9] is an RMI invoker 04.03.2012 14:23:15 DEBUG (JdkDynamicAopProxy.java:113) - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.otv.rmi.server.RMIUserService@16dadf9] 04.03.2012 14:23:15 INFO (RmiServiceExporter.java:276) - Binding service 'RMIUserService' to RMI registry: RegistryImpl[UnicastServerRef [liveRef: [endpoint:[192.168.1.7:1099](local),objID:[0:0:0, 0]]]] 04.03.2012 14:23:15 DEBUG (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.remoting.rmi.RmiServiceExporter#0' 04.03.2012 14:23:15 DEBUG (AbstractApplicationContext.java:845) - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@3c0007] 04.03.2012 14:23:15 DEBUG (AbstractBeanFactory.java:245) - Returning cached instance of singleton bean 'lifecycleProcessor'04.03.2012 14:25:43 DEBUG (RemoteInvocationTraceInterceptor.java:73) - Incoming RmiServiceExporter remote call: com.otv.rmi.server.IRMIUserService.addUser 04.03.2012 14:25:43 DEBUG (RMIUserService.java:33) - User has been added to cache. User : Id : 1, Name : Bruce, Surname : Willis 04.03.2012 14:25:43 DEBUG (RemoteInvocationTraceInterceptor.java:79) - Finished processing of RmiServiceExporter remote call: com.otv.rmi.server.IRMIUserService.addUser04.03.2012 14:25:43 DEBUG (RemoteInvocationTraceInterceptor.java:73) - Incoming RmiServiceExporter remote call: com.otv.rmi.server.IRMIUserService.getUserList 04.03.2012 14:25:43 DEBUG (RMIUserService.java:57) - User List : [Id : 1, Name : Bruce, Surname : Willis] 04.03.2012 14:25:43 DEBUG (RemoteInvocationTraceInterceptor.java:79) - Finished processing of RmiServiceExporter remote call: com.otv.rmi.server.IRMIUserService.getUserList04.03.2012 14:25:43 DEBUG (RemoteInvocationTraceInterceptor.java:73) - Incoming RmiServiceExporter remote call: com.otv.rmi.server.IRMIUserService.deleteUser 04.03.2012 14:25:43 DEBUG (RMIUserService.java:45) - User has been deleted from cache. User : Id : 1, Name : Bruce, Surname : Willis 04.03.2012 14:25:43 DEBUG (RemoteInvocationTraceInterceptor.java:79) - Finished processing of RmiServiceExporter remote call: com.otv.rmi.server.IRMIUserService.deleteUser04.03.2012 14:25:43 DEBUG (RemoteInvocationTraceInterceptor.java:73) - Incoming RmiServiceExporter remote call: com.otv.rmi.server.IRMIUserService.getUserList 04.03.2012 14:25:43 DEBUG (RMIUserService.java:57) - User List : [] 04.03.2012 14:25:43 DEBUG (RemoteInvocationTraceInterceptor.java:79) - Finished processing of RmiServiceExporter remote call: com.otv.rmi.server.IRMIUserService.getUserList

步驟13:下載

OTV_SpringRMI

參考: Online Technology Vision博客中的JCG合作伙伴 Eren Avsarogullari的Spring Remoting支持和RMI服務(wù)開發(fā) 。


翻譯自: https://www.javacodegeeks.com/2012/04/spring-remoting-support-and-developing.html

總結(jié)

以上是生活随笔為你收集整理的Spring远程支持和开发RMI服务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。