Web Service是一种传统的远程过程调用方式,它通过XML来定义服务信息和传输数据。Dubbo是一种分布式服务治理框架,它提供了服务注册与发现,负载均衡,远程调用等。Dubbo在进行服务调用时,默认使用Dubbo 自定义的协议,但也支持各种第三方协议,如rest,grpc,web service等。
Dubbo提供了对Web Service的整合能力,主要是指可以将Web Service包装成Dubbo服务,因此提供了服务注册与发现,同时在提供者端可以让开发者像发布Dubbo服务那样,很简便地发布Web Service服务,在消费者端则可以像调用Dubbo服务那样,调用Web Service服务。
定义服务接口
public interface DemoService {
String hello(String word);
}
提供者整合
因为Web Service需要使用HTTP协议,所以提供者必须使用Web容器(不管是外置的还是嵌入式的)
Web容器配置
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>dubbo-webservice</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>