国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Spring調用Rmi

2019-11-14 09:37:07
字體:
來源:轉載
供稿:網友

    在工作中遇到了多個客戶端調用同一組Service的情況,所以就趕緊測試了一下Rmi,因為程序用的是SPRing框架,所以此處記錄的僅為Spring中調用Rmi的實例說明:

    1. 服務端 B/S端

        a. 增加接口:DpersonInfo

package com.hr;import java.util.List;public interface DpersonInfo {	List<MpersonInfo> getPersonInfoList();	List<MpersonInfo> getPersonInfoList(String ttype);	String getTest(String name);}

        b. 實現接口:DpersonInfoImpl

package com.hr;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.jdbc.core.BeanPropertyRowMapper;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.jdbc.core.RowMapper;import org.springframework.stereotype.Repository;@Repositorypublic class DpersonInfoImpl implements DpersonInfo {	private RowMapper<MpersonInfo> rm=new BeanPropertyRowMapper<>(MpersonInfo.class);	@Autowired	private JdbcTemplate db;		@Override	public List<MpersonInfo> getPersonInfoList() {		String sql="select * from person_info";		return db.query(sql, rm);		//return null;	}	@Override	public List<MpersonInfo> getPersonInfoList(String ttype) {		String sql="select * from person_info where ttype='"+ttype+"'";		//return null;		return db.query(sql, rm);	}	@Override	public String getTest(String name) {		// TODO Auto-generated method stub		return "hello "+name+" rmi start...";	}}

        c. 配置發布接口Bean參數

<bean id="helloWorld" class="com.hr.DpersonInfoImpl" />  <bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">  	<property name="service" ref="helloWorld" />  	<property name="serviceName" value="hello" />  	<property name="serviceInterface" value="com.hr.DpersonInfo" />  	<property name="registryPort" value="8088" />  </bean>

        2. 客戶端 C/S端

            a. 增加接口類:此類和服務端的接口類內容需要一致,即DpersonInfo,名稱可以不一樣,但里面的方法名及參數需要一致。

            b. 增加List中普通的Bean對象:此類和服務端中List集合中的對象類一致,即MpersonInfo類。

            c. spring環境配置

<?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">		       	<bean id="helloWorld" class="org.springframework.remoting.rmi.RmiproxyFactoryBean">  		<property name="serviceUrl" value="rmi://192.168.96.11:8088/hello" />  		<property name="serviceInterface" value="com.hr.DpersonInfo" />  	</bean>        	</beans>

            d. 調用Rmi

package com.hr;import java.util.List;import org.springframework.context.applicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Imain {	public static void main(String[] args) {		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");  		DpersonInfo hs = (DpersonInfo) ctx.getBean("helloWorld");  		System.out.println(hs.getTest("luke"));  		List<MpersonInfo> list=hs.getPersonInfoList();		for(MpersonInfo m:list){			System.out.println(m.toString());		}	}}以上親測可正常使用....


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南皮县| 新野县| 怀远县| 股票| 子洲县| 三原县| 南投县| 丹凤县| 措美县| 禄劝| 会东县| 阳信县| 镇宁| 三江| 客服| 务川| 德庆县| 兴安县| 兖州市| 平果县| 鄂托克前旗| 石城县| 尚义县| 肥东县| 金塔县| 洮南市| 仁怀市| 穆棱市| 渝中区| 巴塘县| 镇巴县| 旬邑县| 皮山县| 武定县| 建水县| 游戏| 枞阳县| 清镇市| 布拖县| 渝中区| 武冈市|