用httpinvoker使兩個系統之間的方法可以互相呼叫
阿新 • • 發佈:2018-11-30
業務場景:兩個系統之間可能存在通訊(方法的呼叫),這時用httpinvoker可以實現輕量級的解決方案
分為服務端和客戶端,客戶端呼叫服務端提供的介面;
客戶端配置:
<bean id="OpenApi4SoaService" class="cn.com.agree.open.mvc.service.impl.openapi.OpenApi4SoaServiceImpl"/> <bean id="httpServiceServer" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service"> <ref bean="OpenApi4SoaService"/> </property> <property name="serviceInterface" value="cn.com.agree.open.mvc.service.api.openapi.OpenApi4SoaService"/> </bean>
服務端配置:
<description>http invoker客戶端代理配置</description> <context:property-placeholder location="classpath:../config/application.properties"/> <bean id="httpService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl"> <value>${soa.httpinvoker.server.url}</value> <!-- <value>http://10.128.81.131:8090/esb-soa/httpService</value> --> </property> <property name="serviceInterface" value="cn.com.agree.soa.web.service.soa.OpenService"></property> </bean> <!-- 2010-10-24 新的治理平臺同步介面 --> <bean id="httpServiceNew" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl"> <value>http://192.9.200.237:8090/aweb_soa/httpService</value> </property> <property name="serviceInterface" value="awb.aweb_soa.httpService.service.GovernmentService"></property> </bean>
可存在多個互相的呼叫。
web.xml配置:
<servlet> <servlet-name>httpServiceServer</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/config/httpinvoker-server-config.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>httpServiceServer</servlet-name> <url-pattern>/httpServiceServer</url-pattern> </servlet-mapping>
然後,服務端提供給客戶端一個jar包,該jar包裡面包含了客戶端需要呼叫的介面的類。eclipse中右鍵export,選擇JAR file。
以上
實現原理見https://blog.csdn.net/zstu_cc/article/details/54743920