spring 自带远程接口实现方法

 <!-- rmi方式 ,不能穿透防火墙-->
    <bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">  
        <property name="service" ref="fileServiceImpl" />  
        <!-- 定义服务名 -->  
        <property name="serviceName" value="RmiFileService" />  
        <property name="serviceInterface" value="com.roiland.interf.FileService" />  
        <property name="registryPort" value="8088" />  
    </bean>  


http://my.oschina.net/linuxfelix/blog/120202


<!--spring invokerService spring自带远程接口服务-->
 <!-- 交给Spring管理,bean的名称是:userServiceabc, com.roiland.cms.pxd.UserInter的实现类-->
<bean id="userServiceabc" class="com.roiland.cms.pxd.impl.UserInterImpl"/>

<!-- 这个配置,就是把userService接口,提供给远程调用 -->
<bean id="httpServiceabc"  class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
           <property name="service">
               <ref bean="userServiceabc" />
          </property>
           <property name="serviceInterface"
               value="com.roiland.cms.pxd.UserInter"><!--为客户端提供的接口,-->
          </property>
    </bean>
    
    <!-- 远程服务的URL  http://www.audi-online.cn:8080/audionline/test.html-->
    <bean
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
         <property name="mappings">
            <props>
                  <prop key="/test.html">httpServiceabc</prop><!--映射访问一个地址test.html-->
            </props>
        </property>
    </bean>


<!--服务端实现类-->
package com.roiland.cms.pxd.impl;


import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;


import org.springframework.web.multipart.MultipartFile;


import com.roiland.cms.pxd.UserInter;


public class UserInterImpl implements UserInter {


@Override
public String add(String name) {
// TODO Auto-generated method stub
String res = "欢迎"+name+"访问接口上传文件";
System.out.println(name+"访问接口");
return res;
}


@Override
public boolean upload(String filename,byte [] b) {
boolean result = false;
if(b.length==0){
return result;
}

try {
String path = System.getProperty("user.dir");
path = path.substring(0,path.indexOf(":"))+"://upload/"+filename;
System.out.println(path+"-----------上传文件");
File file = new File(path);
if(!file.exists()){
file.createNewFile();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
out.write(b);
out.flush();
out.close();
result = true;
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}


@Override
public boolean uploadfile(InputStream is) {
// TODO Auto-generated method stub
if(is!=null){
System.out.println(2222);
}
return false;
}


}
















<!--客户端配置-->
 <bean id="fs" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
      <property name="serviceUrl" value="http://www.audi-online.cn:8080/audionline/test.html"></property>
     
      <property name="serviceInterface" value="com.roiland.cms.pxdinterface.FileService" />  <!--客户端要有这个接口,跟服务端一样,用于接收-->
      </bean>





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值