Build Dubbo + ZooKeeper with Mav
Step 1 Make the service a Dubbo service
![](https://img.haomeiwen.com/i8035672/6305b6d58b2eb772.png)
![](https://img.haomeiwen.com/i8035672/faeb15d6229f7fe8.png)
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>
![](https://img.haomeiwen.com/i8035672/2dd5fda74918ca6f.png)
![](https://img.haomeiwen.com/i8035672/a5063601863f493b.png)
![](https://img.haomeiwen.com/i8035672/9515d441a8adb295.png)
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>
![](https://img.haomeiwen.com/i8035672/266f0258a0f3fe94.png)
Open HelloService.java
, cursor above the declaration of the method and start typing @Autowired
![](https://img.haomeiwen.com/i8035672/c988d72c7bfb53cd.png)
![](https://img.haomeiwen.com/i8035672/f338edbfd88714c8.png)
Step 3 Take a break here and compile, to see it works.
![](https://img.haomeiwen.com/i8035672/9865ffe843e261b3.png)
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.
![](https://img.haomeiwen.com/i8035672/ca6cde94158cfa29.png)
![](https://img.haomeiwen.com/i8035672/5c7af2b16533c5ed.png)
![](https://img.haomeiwen.com/i8035672/e2bf52ff1b1e8867.png)
![](https://img.haomeiwen.com/i8035672/64a76aaedf61c7bc.png)
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
![](https://img.haomeiwen.com/i8035672/88f4cafe57476dee.png)
It should be an XML file, and its name should be the same as the one in code.
![](https://img.haomeiwen.com/i8035672/68151b103684b0fd.png)
Declare that it uses dubbo-protocol to work with zookeeper
![](https://img.haomeiwen.com/i8035672/142f3ebc09bc3256.png)
![](https://img.haomeiwen.com/i8035672/85c6fde194a4ccad.png)
![](https://img.haomeiwen.com/i8035672/9572b2c9b9f5bb62.png)
Step 6 Try to run it
![](https://img.haomeiwen.com/i8035672/59f5b73f629c94e5.png)
![](https://img.haomeiwen.com/i8035672/2a6cae0f921ed6ba.png)
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.