1、remoting-servlet.xml
备注:该文件必须放在“WEB-INF/”下面。
2、remoting-client.xml
3、web.xml配置
4、调用方法
方法一:
备注:基于“remoting-client.xml”的配置
方法二:
5、优缺点和注意事项
1.优缺点
优点:效率高,几乎跟调用本地接口一样
缺点:不跨平台
2.注意事项
remoting服务 正好与 rest服务 互补,在参数传递和返回值上完全没有限制,能满足java用户的全部需求。
该文章基于上篇文章(rest服务例子:[url]http://hdxiong.iteye.com/admin/blogs/998069[/url])
<?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])