remoting服务例子

1、remoting-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//Spring//DTD Bean//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean name="/hello/find" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="helloImpl" />
<property name="serviceInterface" value="com.IHello" />
</bean>
</beans>

备注:该文件必须放在“WEB-INF/”下面。

2、remoting-client.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//Spring//DTD Bean//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean name="testRemote" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/Test/remoting/hello/find" />
<property name="serviceInterface" value="com.inf.IHello" />
</bean>
</beans>


3、web.xml配置

<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>


4、调用方法
方法一:

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
IHello hello = (IHello)context.getBean("testRemote");
Result result = hello.findByName("jack");
System.out.println(result.getLstUser().size());

备注:基于“remoting-client.xml”的配置

方法二:

//免配置
HttpInvokerProxyFactoryBean bean=new HttpInvokerProxyFactoryBean();
bean.setServiceUrl("http://localhost:8080/Test/remoting/hello/find");
bean.setServiceInterface(IHello.class);
bean.afterPropertiesSet();//必须
IHello hello = (IHello)bean.getObject();
Result result = hello.findByName("jack");
System.out.println(result.getLstUser().size());


5、优缺点和注意事项
1.优缺点
优点:效率高,几乎跟调用本地接口一样
缺点:不跨平台
2.注意事项
remoting服务 正好与 rest服务 互补,在参数传递和返回值上完全没有限制,能满足java用户的全部需求。

该文章基于上篇文章(rest服务例子:[url]http://hdxiong.iteye.com/admin/blogs/998069[/url])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值