⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spring实现rmi详解.txt

📁 RMI非常经典的实例+PPT说明(step by step)
💻 TXT
字号:
1.1服务端
1.1.1服务接口
package cn.webservice;
 
import java.util.List;
 
publicinterface AccountService {
 
    publicvoid insertAccount(Integer account);
    public List getAccounts(String name);
}
1.1.2服务实现类
package cn.webservice;
 
import java.util.List;
 
publicclass AccountServiceImplement implements AccountService {
 
    public List getAccounts(String name) {
       // TODO Auto-generated method stub
       System.out.println("getAccounts successful!"+name);
       returnnull;
    }
 
    publicvoid 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;
 
publicclass Demo {
 
    publicstaticvoid 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;
 
publicinterface AccountService {
    publicvoid 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;
 
publicclass Demo {
    publicstaticvoid main(String[] args) {
       ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
       AccountService service = (AccountService)ctx.getBean("accClient");
       service.insertAccount(new Integer(588));
       service.getAccounts("songwenpeng");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -