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

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

Spring調用Rmi

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

    在工作中遇到了多個客戶端調用同一組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());		}	}}以上親測可正常使用....


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴义市| 吉安市| 莱州市| 东宁县| 阳西县| 阳江市| 岐山县| 揭阳市| 布尔津县| 汾阳市| 清水河县| 堆龙德庆县| 锡林郭勒盟| 枞阳县| 南安市| 资兴市| 赣榆县| 阿克苏市| 宁安市| 贡嘎县| 长阳| 女性| 洪洞县| 萨迦县| 双桥区| 石柱| 河间市| 凉山| 聂拉木县| 九龙城区| 汾西县| 阳城县| 南雄市| 建瓯市| 安阳县| 南丹县| 仪征市| 庆阳市| 新和县| 托克托县| 会东县|