spring_webservice_rmi配置示例


服务器端: 
spring_webservice_rmi配置示例_第1张图片

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
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 ;
">
  
 
 
 
     
   
   
   
   
   
  
 
  
     
 


web.xml
        
      contextConfigLocation       
      classpath:applicationContext.xml   
        
 
     org.springframework.web.context.ContextLoaderListener 
   
 

发布==》

调用服务器
spring_webservice_rmi配置示例_第2张图片

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 
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 ;
">
   
 
 
   
   
   


     


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();
}
 
 }
     
}

 运行测试ok

你可能感兴趣的:(java,spring,JAVA,spring)