通過http調用方法(利用spring)

一、 服務器端
1. 配置web.xml

xml 代碼
  1. <servlet>  
  2. <servlet-name>httpremote</servlet-name>  
  3. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  4. <load-on-startup>1</load-on-startup>  
  5. </servlet>  
  6. <servlet-mapping>  
  7. <servlet-name>httpremote</servlet-name>  
  8. <url-pattern>/remoting/*</url-pattern>  
  9. </servlet-mapping>  

2. 在WEB-INF下面建立一個應用上下文的xml文件,命名規範是servlet的名稱,加上一個“-servlet.xml”,例如httpremote-servlet.xml

xml 代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">  
  3.   
  4. <beans>  
  5. <bean id="accountService" class="com.excellence.webservice.AccountServiceImpl" />  
  6. <bean name="/AccountService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">  
  7. <property name="service" ref="accountService"></property>  
  8. <property name="serviceInterface" value="com.excellence.webservice.AccountService"></property>  
  9. </bean>  
  10.   
  11. </beans>  
二、 客戶端
在spring的配置文件中配置一個http調用代理即可。
xml 代碼
  1. <bean id="httpInvokeProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">  
  2. <property name="serviceUrl" value="http://localhost/springHttpInvoke/remoting/AccountService"></property>  
  3. <property name="serviceInterface" value="com.excellence.webservice.AccountService"></property>  
  4. </bean>  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章