您好,登錄后才能下訂單哦!
普通接口及實現類
public interface WsService
{
String sayHello(String msg);
}
public class WsServiceImpl implements WsService
{
@Override
public String sayHello(String msg)
{
return "hello " + msg;
}
}
dubbo服務提供者配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方應用信息,用于計算依賴關系 -->
<dubbo:application name="dubbo-webservice-app-provider" />
<!-- <dubbo:registry protocol="multicast" address="224.5.6.7:1234"/> -->
<!-- 如果server:servlet,則端口必須與servlet容器端口一致,同時contextpath與servlet應用的上下文相同 -->
<dubbo:protocol name="webservice" port="8080" server="servlet"/>
<dubbo:service interface="com.dubbo.webservice.WsService" ref="wsService" registry="N/A" path="service" />
<bean id="wsService" class="com.dubbo.webservice.WsServiceImpl" />
</beans>
dubbo服務消費者配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方應用信息,用于計算依賴關系 -->
<dubbo:application name="dubbo-webservice-app-consumer"/>
<!-- 使用multicast廣播注冊中心暴露服務地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234"/> -->
<!-- 聲明需要暴露的服務接口 -->
<dubbo:reference interface="com.dubbo.webservice.WsService" id="wsService" url="webservice://localhost:8080/ProjectBuild/service" registry="N/A"/>
</beans>
web.xml配置
<servlet>
<servlet-name>dubbo</servlet-name>
<servlet-class>com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dubbo</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
依賴配置文件
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.6.1</version>
</dependency>
注意事項
需要指定<dubbo:protocol server="servlet">.
jar需要使用2.6.1版本,使用高版本好像有問題,消費者無法訪問.
消費者引用時,url需要帶上應用上下文,否則也無法訪問.
針對servlet的服務,端口和上下文必須與應用服務器的端口及上下文保持一致.
遺留問題
1.dubbo-webservice與標準webservice的相互使用
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。