Spring 发布 RMI (服务端)

上一篇 / 下一篇  2008-04-28 22:32:01 / 个人分类:spring

服务端

packageremote.rmi;

 

importjava.io.Serializable;

 

publicclassAccountimplementsSerializable{

 

   /**

    *

    */

   privatestaticfinallongserialVersionUID= 1L;

   

   privateStringname;

 

   publicString getName() {

      returnname;

   }

 

   publicvoidsetName(String name) {

      this.name= name;

   }

   

   

 

}

 

 

远程接口:

 

packageremote.rmi;

 

importjava.rmi.Remote;

importjava.rmi.RemoteException;

importjava.util.List;

 

publicinterfaceAccountServiceextendsRemote{

   

   publicvoidinsertAccount(Account account)throwsRemoteException;

   publicList<Account> getAccount(String name)throwsRemoteException;

   

 

}

 

 

接口实现类:

packageremote.rmi;

 

importjava.rmi.RemoteException;

importjava.util.List;

 

publicclassAccountServiceImpimplementsAccountService{

 

   @Override

   publicList<Account> getAccount(String name)throwsRemoteException {

      //TODOAuto-generated method stub

      String text="Hello "+name;

      System.out.println(text);

      returnnull;

   }

 

   @Override

   publicvoidinsertAccount(Account account)throwsRemoteException {

      //TODOAuto-generated method stub

      

   }

 

}

 

 

XML

 

<?xmlversion="1.0"encoding="UTF-8"?>

<!DOCTYPEbeansPUBLIC"-//SPRING//DTD BEAN 2.0//EN""http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

   <beanid="accountService"class="remote.rmi.AccountServiceImp">

   </bean>

 

   <beanclass="org.springframework.remoting.rmi.RmiServiceExporter">

      <propertyname="serviceName"value="AccountService"></property>

      <propertyname="service">

          <reflocal="accountService"/>

      </property>

      <propertyname="serviceInterface"

          value="remote.rmi.AccountService">

      </property>

      <propertyname="registryPort"value="8080"></property>

   </bean>

</beans>

 

 

服务器:

packageremote.rmi;

 

importorg.springframework.context.ApplicationContext;

importorg.springframework.context.support.ClassPathXmlApplicationContext;

 

publicclassService {

   publicstaticvoidmain(String args[]) {

      ApplicationContext context =newClassPathXmlApplicationContext(

             "/remote/rmi/rmi.xml");

      

      AccountServiceservice=(AccountService) context.getBean("accountService");

      

   }

 

}

 

 

启动Service


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-07-26  
  12345
6789101112
13141516171819
20212223242526
2728293031  

数据统计

  • 访问量: 223
  • 日志数: 11
  • 建立时间: 2007-12-21
  • 更新时间: 2008-05-17

RSS订阅

Open Toolbar