Spring中HttpInvoker实例
2010-03-25 14:03
465 查看
Spring版本2.5.6.SEC01
1.服务端:
需要如下jar包:spring.jar spring-webmvc.jar
IPersonService.java
PersonServiceImpl.java
service-config.xml
web.xml添加如下代码
2.客户端:
客户端需要应用服务端的bean和接口,另外需要spring.jar
HttpInvokerClient.java
httpinvoker-client.xml
注意:ProjectContextRoot对应.mymetadata中的context-root,如果修改,需要重新启动Eclipse
1.服务端:
需要如下jar包:spring.jar spring-webmvc.jar
IPersonService.java
public interface IPersonService { public String queryPersonName(); }
PersonServiceImpl.java
public class PersonServiceImpl implements IPersonService { public String queryPersonName() { return "test"; } }
service-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <bean id="personService" class="com.travelsky.angel.service.impl.PersonServiceImpl" /> <bean id="serviceExporter" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service" ref="personService" /> <property name="serviceInterface" value="com.travelsky.angel.service.IPersonService" /> </bean> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/person.service">serviceExporter</prop> </props> </property> </bean> </beans>
web.xml添加如下代码
<servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/service-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>*.service</url-pattern> </servlet-mapping>
2.客户端:
客户端需要应用服务端的bean和接口,另外需要spring.jar
HttpInvokerClient.java
public class HttpInvokerClient { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("httpinvoker-client.xml"); IPersonService service = (IPersonService) context.getBean("personServiceProxy"); String result = service.queryPerson(); System.out.println(result); } }
httpinvoker-client.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <bean id="personServiceProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl" value="http://127.0.0.1:8080/ProjectContextRoot/person.service" /> <property name="serviceInterface" value="com.travelsky.angel.service.IPersonService" /> </bean> </beans>
注意:ProjectContextRoot对应.mymetadata中的context-root,如果修改,需要重新启动Eclipse
相关文章推荐
- Spring中HttpInvoker实例
- Spring中HttpInvoker远程方法调用使用实例
- Spring HTTP Remote Invoker的一个问题
- Spring HttpInvoker(二)
- 深入学习 Spring HttpInvoker
- Spring HTTP Invoker使用介绍
- Spring Remoting: HTTP Invoker--转
- Spring HttpInvoker源码分析
- Spring Httpinvoker简单Demo
- Spring远程调用技术<3>-Spring的HTTP Invoker
- Spring HttpInvoker(二)
- Spring Http Invoker使用简介
- Spring HttpInvoker
- Spring中HttpInvoker远程方法调用总结
- Spring HTTP invoker 入门
- spring-remoting入门(http-invoker,hessian,burlap)
- Spring HTTP invoker原理
- RMI在Spring中的使用之HttpInvokerServiceExporter
- 关于spring的httpInvoker学习
- SpringHttpInvoker解析1-使用示例