一、 服务器端
1. 配置web.xml
xml 代码
- <servlet>
- <servlet-name>httpremote</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>httpremote</servlet-name>
- <url-pattern>/remoting/*</url-pattern>
- </servlet-mapping>
2. 在WEB-INF下面建立一个应用上下文的xml文件,命名规范是servlet的名称,加上一个“-servlet.xml”,例如httpremote-servlet.xml
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 id="accountService" class="com.excellence.webservice.AccountServiceImpl" />
- <bean name="/AccountService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
- <property name="service" ref="accountService"></property>
- <property name="serviceInterface" value="com.excellence.webservice.AccountService"></property>
- </bean>
-
- </beans>
二、 客户端
在spring的配置文件中配置一个http调用代理即可。
xml 代码
- <bean id="httpInvokeProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
- <property name="serviceUrl" value="http://localhost/springHttpInvoke/remoting/AccountService"></property>
- <property name="serviceInterface" value="com.excellence.webservice.AccountService"></property>
- </bean>