Spring实现RMI

1.1服务端
1.1.1服务接口
package cn.webservice;
import java.util.List;
public interface AccountService {
public void insertAccount(Integer account);
public List getAccounts(String name);
}
1.1.2服务实现类
package cn.webservice;
import java.util.List;
public class AccountServiceImplement implements AccountService {
public List getAccounts(String name) {
// TODO Auto-generated method stub
System. out .println( "getAccounts successful!" +name);
return null ;
}
public void insertAccount(Integer account) {
// TODO Auto-generated method stub
System. out .println( "insertAccount successful" +account.toString());
}
}
1.1.3配制文件
< bean id = "accountService"
class = "cn.webservice.AccountServiceImplement" />
< bean name = "service"
class = "org.springframework.remoting.rmi.RmiServiceExporter" >
< property name = "serviceName" value = "AccountService" ></ property >
< property name = "service" ref = "accountService" ></ property >
< property name = "serviceInterface"
value = "cn.webservice.AccountService" >
</ property >
< property name = "registryPort" value = "1199" ></ property >
</ bean >
1.1.4运行Service
package cn.webservice;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.remoting.rmi.RmiServiceExporter;
public class Demo {
public static void main(String[] args) {
ApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:applicationContext.xml" );
RmiServiceExporter obj = (RmiServiceExporter)ctx.getBean( "service" );
}
}
1.2客户端
1.2.1接口文件
package cn.testspringrmi;
import java.util.List;
public interface AccountService {
public void insertAccount(Integer account);
public List getAccounts(String name);
}
1.2.2配置文件
< bean id = "accClient"
class = "org.springframework.remoting.rmi.RmiProxyFactoryBean" >
< property name = "serviceUrl"
value = "rmi://localhost:1199/AccountService" >
</ property >
< property name = "serviceInterface"
value = "cn.testspringrmi.AccountService" >
</ property >
</ bean >
1.2.3服务调用
package cn.testspringrmi;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Demo {
public static void main(String[] args) {
ApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:applicationContext.xml" );
AccountService service = (AccountService)ctx.getBean( "accClient" );
service.insertAccount( new Integer(588));
service.getAccounts( "songwenpeng" );
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值