Spring为各种远程访问技术的集成提供了工具类。Spring远程支持是由普通(Spring)POJO实现的,这使得开发具有远程访问功能的服务变得相当容易。目前,Spring支持四种远程技术:
public interface IRemoteService {
public void startRmote();
}
public class RemoteServiceImpl implements IRemoteService {
@Override
public void startRmote() {
// TODO Auto-generated method stub
System.out.println("this is remote --------------------------------");
}
}
<?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="remote" class="com.frame.rmote.RemoteServiceImpl" /> <bean name="/remoteservice" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service" ref="remote" /> <property name="serviceInterface" value="com.frame.rmote.IRemoteService" /> </bean> </beans>
<servlet>
<servlet-name>testRemote</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>testRemote</servlet-name>
<url-pattern>/testRemoting/*</url-pattern>
</servlet-mapping>服务端配置完毕public interface IRemoteService {
public void startRmote();
}
<bean id="iRemoteTest" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl" value="http://localhost:8080/Frame/testRemoting/remoteservice" /> <property name="serviceInterface" value="mf.newrise.test.IRemoteService" /> </bean>
public class TestRemote {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
IRemoteService service = (IRemoteService) applicationContext.getBean("iRemoteTest")
service.startRemote();
}
}Spring中HttpInvoker远程方法调用总结,布布扣,bubuko.com
原文地址:http://blog.csdn.net/oyyz111/article/details/37533709