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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring rmi

發布時間:2025/3/21 javascript 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring rmi 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

1.org.springframework.remoting.rmi.RmiProxyFactoryBean

其使用的是rmi協議實現

實現過程,首先是服務端

定義一個導出類

?
1 2 3 public? interface? AccountService?{ ???? String?getUsername(); }

?

?
1 2 3 4 5 6 public? class? AccountServiceImpl? implements? AccountService{ ???? @Override ???? public? String?getUsername()?{ ???????? return? "RMI?Test!" ; ???? } }

?

rmi.xml

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <? xml? version = "1.0"? encoding = "UTF-8" ?> < beans? xmlns = "http://www.springframework.org/schema/beans" ??????? xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" ??????? xsi:schemaLocation="http://www.springframework.org/schema/beans ???????? http://www.springframework.org/schema/beans/spring-beans.xsd"> ???? < bean? id = "accountService"? class = "example.AccountServiceImpl" > ???????? <!--?any?additional?properties,?maybe?a?DAO??--> ???? </ bean > ???? < bean? class = "org.springframework.remoting.rmi.RmiServiceExporter" > ???????? <!--?這里的服務名可以隨意填寫但是必須和rmi://hostname:1199/xxxxxxx的xxxxxxx相同?--> ???????? < property? name = "serviceName"? value = "AccountService" /> ???????? <!--?導出實體?--> ???????? < property? name = "service"? ref = "accountService" /> ???????? <!--?導出接口,這個為導出接口,注意,客戶端包名可以和這里不同,但是為了統一建議做一個coreInterface ???????????? 包,以便以后維護方便?--> ???????? < property? name = "serviceInterface"? value = "example.AccountService" /> ???????? <!--?端口號,默認為1099,這里注意占用問題?--> ???????? < property? name = "registryPort"? value = "1199" /> ???? </ bean > </ beans >

?

啟動服務

?
1 2 3 4 5 6 7 8 9 public? class? Main?{ ???? public? static? void? main(String[]?args)?{ ???????? ApplicationContext?context?= ???????????????? new? ClassPathXmlApplicationContext( "rmi.xml" ); ???????? AccountService?service?=?context.getBean( "accountService" ,?AccountService. class ); ???????? String?userName?=?service.getUsername(); ???????? System.out.println(userName); ???? } }

?

?

接下來客戶端如下

?
1 2 3 public? interface? AccountService?{ ???? String?getUsername(); }

?

rmi.xml

?
1 2 3 4 5 6 7 8 9 10 11 12 13 <?xml?version= "1.0"? encoding= "UTF-8" ?> <beans?xmlns= "http://www.springframework.org/schema/beans" ??????? xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" ??????? xsi:schemaLocation="http: //www.springframework.org/schema/beans ???????? http: //www.springframework.org/schema/beans/spring-beans.xsd"> ???? <bean?id= "accountService"? class = "org.springframework.remoting.rmi.RmiProxyFactoryBean" > ???????? <!--?接收的rmi協議?--> ???????? <property?name= "serviceUrl"? value= "rmi://localhost:1199/AccountService" /> ???????? <!--?接收的rmi協議的接口?--> ???????? <property?name= "serviceInterface"? value= "example.AccountService" /> ???? </bean> </beans>

?

啟動程序

?
1 2 3 4 5 6 7 8 9 public? class? Main?{ ???? public? static? void? main(String[]?args)?{ ???????? ApplicationContext?context?= ???????????????? new? ClassPathXmlApplicationContext( "rmi.xml" ); ???????? AccountService?service?=?context.getBean( "accountService" ,?AccountService. class ); ???????? String?userName?=?service.getUsername(); ???????? System.out.println(userName); ???? } }

?

這樣就可以在服務器端得到了RMI Test!

當我們在啟動服務端的時候會發現,其控制臺一直在運行狀態,當結束后,還會有rmi進程在運行。其接口協議為rmi://hostname:1199/xxxxxxx

?

轉載于:https://my.oschina.net/u/264186/blog/638117

總結

以上是生活随笔為你收集整理的Spring rmi的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。