spring_webservice_rmi配置示例
来源:互联网 发布:淘宝vip福利群 编辑:程序博客网 时间:2024/05/17 22:34
服务器端:
Userinfo.java
package com.lilin.entity;
IUserinfoService.java
UserinfoServiceImpl.java
web.xml
Userinfo.java
package com.lilin.entity;
import java.io.Serializable;
public class Userinfo implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
IUserinfoService.java
package com.lilin.iservice;
import com.lilin.entity.Userinfo;
public interface IUserinfoService {
public void addUserinfo(Userinfo userinfo) throws Exception;
}
UserinfoServiceImpl.java
package com.lilin.serviceimpl;
import com.lilin.entity.Userinfo;
import com.lilin.iservice.IUserinfoService;
public class UserinfoServiceImpl implements IUserinfoService{
public void addUserinfo(Userinfo userinfo) throws Exception{
System.out.println("添加了一个新的用户"+userinfo.getName());
}
}
applicationContext.xml
</beans>
applicationContext.xml
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans ;
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop ;
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx ;
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ;
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/cache ;
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd ;
">
<bean id="userinfoService" class="com.lilin.serviceimpl.UserinfoServiceImpl"></bean>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<!-- does not necessarily have to be the same name as the bean to be exported -->
<property name="serviceName" value="UserinfoService"/>
<property name="service" ref="userinfoService"/>
<property name="serviceInterface" value="com.lilin.iservice.IUserinfoService"/>
<!-- defaults to 1099 -->
<property name="registryPort" value="1199"/>
</bean>
web.xml
<!-- load spring begin-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- load spring end-->
发布==》
调用服务器
userinfo.java 和 IUserinfoService.java同上
SimpleObject.java
App.java
运行测试ok
发布==》
调用服务器
userinfo.java 和 IUserinfoService.java同上
SimpleObject.java
package com.lilin.test;
import com.lilin.entity.Userinfo;
import com.lilin.iservice.IUserinfoService;
public class SimpleObject {
private IUserinfoService iUserinfoService;
public IUserinfoService getiUserinfoService() {
return iUserinfoService;
}
public void setiUserinfoService(IUserinfoService iUserinfoService) {
this.iUserinfoService = iUserinfoService;
}
public void add(Userinfo name) throws Exception{
iUserinfoService.addUserinfo( name );
}
}
applicationContext.xml
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans ;
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop ;
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx ;
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ;
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/cache ;
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd ;
">
<bean id="accountService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://localhost:1199/UserinfoService"/>
<property name="serviceInterface" value="com.lilin.iservice.IUserinfoService"/>
</bean>
<bean id="test" class="com.lilin.test.SimpleObject">
<property name="iUserinfoService" ref="accountService"/>
</bean>
</beans>
App.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.lilin.entity.Userinfo;
import com.lilin.test.SimpleObject;
public class App {
@org.junit.Test
public void test(){
ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");
SimpleObject object = (SimpleObject) context.getBean("test");
try {
Userinfo userinfo = new Userinfo();
userinfo.setName("=>李林");
object.add(userinfo);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- spring_webservice_rmi配置示例
- OSPF配置示例
- Bean配置示例
- tomcat配置数据源示例
- spring事物配置示例
- SVN 配置示例
- TOMCAT配置示例
- Struts2.0配置示例
- CAS client配置示例
- OpenNMS配置Gmail示例
- apche虚拟机配置示例
- YsuhyORM 配置 示例数据库
- svn配置示例
- SSH配置模板示例
- DirectSound示例的配置
- apache虚拟主机配置示例
- struts配置示例
- Velocity.properties配置示例
- ubunt recovery模式下,获得写权限
- HTTP协议:状态码详解
- 什么的图形化编程软件能编写控制硬件设备的程序的?
- 继承访问控制
- VC/MFC 判断操作系统
- spring_webservice_rmi配置示例
- 二叉树的先序、中序、后序遍历的递归和非递归实现
- C#中几种换行符
- 一个奇怪的listview
- js 上移 下移 左移 右移
- win7 刻录光盘
- static和final关键字
- 探索 ConcurrentHashMap 高并发性的实现机制
- 【LeetCode】Merge Two Sorted Lists