springboot下的dubbo、zookeeper 結合使用

近期在研究dubbo框架spring

相信看到這篇博客的,dubbo的基礎應該都有了docker

zookeeper的搭建走了點彎路,配置起來各類麻煩,媽的搞的好煩。springboot

正好一直想用一下docker,但對docker只是有個簡單的概念。app

用了一夜去研究docker,以後發現真的好用框架

搭建個zookeeper就跟玩似的。ide

這裏記錄一下遇到的一些坑!網站

一、springboot引入dubbo的配置文件
網上搜索了一下,大概的兩種方式spa

一、 這種方式是經過 ClassPathXmlApplicationContext 加載xml來獲取上下文Context啓動.net

1 @SpringBootApplication
2 3 public class WreserveApplication {

5 public static void main(String[] args) throws IOException, InterruptedException {
6 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"dubbo-provider.xml"});
7 context.start();
8 System.in.read(); // press any key to exit
9 }
10 
11 }
二、經過 @ImportResource({ "classpath:dubbo-provider.xml" }) 加載。code

1 @SpringBootApplication
2 @ImportResource({ "classpath:dubbo-provider.xml" })
3 public class WreserveApplication {
4 @Bean
5 public CountDownLatch closeLatch() {
6 return new CountDownLatch(1);
7 }

9 public static void main(String[] args) throws IOException, InterruptedException {
10 ConfigurableApplicationContext context = SpringApplication.run(WreserveApplication.class, args);
11 CountDownLatch closeLatch = context.getBean(CountDownLatch.class);
12 closeLatch.await();
13 
14 }
15 
16 }
二、dubbo-provider.xml和dubbo-consumer.xml中須要注意的一些問題
dubbo-provider.xml

<?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/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">;

<dubbo:application name="demo-provider"/>
<!-- use multicast registry center to export service -->
<dubbo:registry address="zookeeper://192.168.99.100:2181"/>
<!-- use dubbo protocol to export service on port 20880 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- service implementation, as same as regular local bean -->
<bean id="helloService" class="com.zhyonk.service.Impl.HelloServiceImpl"/>
<!-- declare the service interface to be exported -->
<dubbo:service interface="com.zhyonk.service.HelloService" ref="helloService"/>

</beans>
dubbo-consumer.xml

一、消費者要訪問提供者,

<dubbo:reference id="helloService"
interface="com.zhyonk.wreserve.service.HelloService" protocol="dubbo"

其中的interface必需要求同一個路徑之下,否則對應不上,會出現下面的狀況 圖片描述(最多50字) 正常狀況下dubbo-admin中會顯示 圖片描述(最多50字) 二、若是嫌本身搭建麻煩的話能夠直接用用網站自動生成 http://start.dubbo.io/ 圖片描述(最多50字)

喜歡的能夠點個贊哦

相關文章
相關標籤/搜索