dubbo之webservice協議使用

來源:互聯網
上載者:User

標籤:dubbo webservice

普通介面及實作類別

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>


注意事項

  1. 需要指定<dubbo:protocol server="servlet">.

  2. jar需要使用2.6.1版本,使用高版本好像有問題,消費者無法訪問.

  3. 消費者引用時,url需要帶上應用上下文,否則也無法訪問.

  4. 針對servlet的服務,連接埠和上下文必須與應用伺服器的連接埠及上下文保持一致.


遺留問題

1.dubbo-webservice與標準webservice的相互使用

本文出自 “旅行者” 部落格,請務必保留此出處http://881206524.blog.51cto.com/10315134/1924889

dubbo之webservice協議使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.