Build Dubbo + ZooKeeper with Mav
Step 1 Make the service a Dubbo service


Here, we need to add an exclusion section inside the dependency-secion, to strike with some pitfall from dubbo
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>



Step 2 Import Spring and make use of its annotation
Open 'pom.xml' again, and add the below dependency block into 'dependencies' section.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>

Open HelloService.java
, cursor above the declaration of the method and start typing @Autowired


Step 3 Take a break here and compile, to see it works.

Step 4 Add a main-entry to the project
Till now, we didn't have a main-entry for the project, now let's add it.




We specified a dubbo-provider.xm
to create the context, which we never see before. We will create it now.
Step 5 Create the XML file to define the usage of ZooKeeper server

It should be an XML file, and its name should be the same as the one in code.

Declare that it uses dubbo-protocol to work with zookeeper



Step 6 Try to run it


From the exception message, we know that it relates to something about ZooKeeper.
The reason is that we didn't add a dependency to ZooKeeper.
In the next article, we will fix it.