Dubbo Learning Service Provider

Source: Internet
Author: User

1. Introduction

The main document here is how to build a spring framework that provides a Dubbo service, including detailed steps.

2. Detailed steps

2.1 Project directory Structure

        

2.2 Creating a Maven project

New---Web Project, check add maven support, adding MAVEN supports, as detailed below:

    

    

    

    

    

Create a MAVEN project and you can deploy it to Tomcat and test it for access.

2.3 Adding Maven Dependencies

Modify the Pom.xml, load the underlying spring jar package and the Dubbo jar package as follows:

<Properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    <spring-version>4.1.6.RELEASE</spring-version>  </Properties>    <Dependencies>      <Dependency>          <groupId>Org.springframework</groupId>          <Artifactid>Spring-core</Artifactid>          <version>${spring-version}</version>      </Dependency>      <Dependency>          <groupId>Org.springframework</groupId>          <Artifactid>Spring-context</Artifactid>          <version>${spring-version}</version>      </Dependency>      <Dependency>          <groupId>Org.springframework</groupId>          <Artifactid>Spring-web</Artifactid>          <version>${spring-version}</version>      </Dependency>      <Dependency>      <groupId>Com.alibaba</groupId>      <Artifactid>Dubbo</Artifactid>      <version>2.6.2-snapshot</version>    </Dependency>        </Dependencies>

2.4 Modify the Applicationcontext-base.xml configuration file and add the Dubbo configuration as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:jee= "Http://www.springframework.org/schema/jee"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"xmlns:d= "Http://code.alibabatech.com/schema/dubbo"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.1.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context /spring-context-3.1.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop-3.1.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-3.1.xsd Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/ Spring-jee-3.1.xsd Http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd " >        <!--provider app information for calculating dependencies -    <d:applicationname= "Dubbo_provider"  />    <!--exposing services on 20880 ports with the Dubbo protocol -    <D:protocolname= "Dubbo"Port= "20880" />    <!--exposing a service address using the Zookeeper cluster registry-
<!--here is a pseudo-cluster method, refer to "Zookeeper Initial *********" blog section---
<D:registryAddress= "zookeeper://192.168.1.102:2181?backup=192.168.1.102:2182,192.168.1.102:2183"default= "true" /> <!--declaring a service interface that needs to be exposed - <D:serviceInterface= "Com.wei.interfaces.DemoService"ref= "Demoservice" /> <!--implement services just like local services - <BeanID= "Demoservice"class= "Com.wei.services.DemoServiceImpl" /> </Beans>

2.5 Modify the Web. Xml as follows:

  <Listener>      <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class>  </Listener>  <Context-param>    <Param-name>Contextconfiglocation</Param-name>    <Param-value>Classpath:*.xml</Param-value>  </Context-param>

2.6 Write the Dubbo interface for external release, as follows:

 Package com.wei.interfaces; /**  @author*/Publicinterface  demoservice    {  public string SayHello (string name);}

2.7 Write the implementation class for the external release Dubbo interface as follows:

 Package com.wei.services; Import Com.wei.interfaces.DemoService;  Public class Implements Demoservice {    @Override    public  string SayHello (string name) {          return "Hello" + name;}    }

2.8 Start the service and view the Dubbo management console as follows:

You can see that the Provider tab page already has IP information, click to see the corresponding service information.

2.8 Points of attention:

(1) The interfaces alone to reach the jar package, after the consumer to use.

(2) The zookeeper address used in this step is the zookeeper pseudo-cluster method in front, and if multiple nodes are not configured, it can be configured as a single node or as a multicast registry.

  

Dubbo Learning Service Provider

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.