搭建dubbo+zookeeper+spring环境-环境篇
环境:mac,Java8,tomcat8
安装zookeeper
安装zookeeper
brew install zookeeper
zookeeper的配置文件在/usr/local/etc/zookeeper/zoo.cfg
启动zookeeper
brew services start zookeeper
windows的同学可以参考:Windows安装和使用zookeeper
编译dubbo
下载dubbo源码:
1 | git clone https://github.com/alibaba/dubbo.git |
提示错误:
1 | [INFO] Scanning for projects... |
发现这丫的域名根本就挂了。。。参考dubbo实践(二)自己动手编译源码,这里我们需要自己安装opensesame这个项目:
1 | git clone https://github.com/alibaba/opensesame.git |
然后再进入dubbo目录下执行mvn clean install -Dmaven.test.skip
还是提示错误:
1 | [ERROR] Failed to execute goal on project dubbo-common: Could not resolve dependencies for project com.alibaba:dubbo-common:jar:2.5.3: Failed to collect dependencies at com.alibaba:fastjson:jar:1.1.8: Failed to read artifact descriptor for com.alibaba:fastjson:jar:1.1.8: Could not transfer artifact com.alibaba:fastjson:pom:1.1.8 from/to opensesame.releases (http://code.alibabatech.com/mvn/releases): Connect to code.alibabatech.com:80 [code.alibabatech.com/119.38.217.15] failed: Connection refused -> [Help 1] |
这是因为opensesame的pom指定了去阿里的仓库上下载,而阿里的仓库现在挂了,所以,修改opensesame的pom文件,注释掉repositories,distributionManagement,pluginRepositories这些标签。还得注释dubbo-parent的pom.xml中的repositories标签。
再次install还是失败。。说com.alibaba:fastjson:pom:1.1.8找不到。上mvnrepository看一下,发现maven仓库上根本就没有这个版本。。。修改dubbo-parent的pom.xml的
<fastjson_version>1.1.8</fastjson_version>
为
<fastjson_version>1.1.15</fastjson_version>
再次install终于成功。
运行dubbo控制台
1 | cd dubbo/dubbo-admin |
遇到错误:
1 | ERROR context.ContextLoader - Context initialization failed |
参考:2.5.4-SNAPSHOT dubbo admin error · Issue #50 · alibaba/dubbo,修改如下:
1、webx的依赖改为3.1.6版;
<dependency>
<groupId>com.alibaba.citrus</groupId>
<artifactId>citrus-webx-all</artifactId>
<version>3.1.6</version>
</dependency>
2、添加velocity的依赖,我用了1.7;
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
3、对依赖项dubbo添加exclusion,避免引入旧spring
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${project.parent.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
4、webx已有spring 3以上的依赖,因此注释掉dubbo-admin里面的spring依赖
<!--<dependency>-->
<!--<groupId>org.springframework</groupId>-->
<!--<artifactId>spring</artifactId>-->
<!--</dependency>-->
再次运行,错误:
1 | [ERROR] Failed to execute goal org.mortbay.jetty:maven-jetty-plugin:6.1.26:run (default-cli) on project dubbo-admin: Failure: Address already in use -> [Help 1] |
修改POM:
1 | <build> |
把原来的8080修改为8081。范围http://localhost:8081/即可看到dubbo控制台。
成功。
如果你和我一样遇到错误,打开一个服务,页面显示404,同时报错:
1 | INFO interceptor.RestfuleUrlRewriter - [DUBBO] REWRITE restful uri /governance/services to uri governance/services.htm?{_type=services, _path=governance/services}, dubbo version: 2.5.4-SNAPSHOT, current host: 192.168.33.1 |
说明你暴露了一个顶级包下的接口类似于DemoServer
,如果你暴露的是com.xx.DemoServer
就不会有这个问题。这个应该是dubbo的一个bug。
环境搭建好了,接下来我们写一个简单的服务提供者和服务消费者的例子。请看搭建dubbo+zookeeper+spring环境-编码篇
参考资料
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错) - 在前进的路上 - 博客频道 - CSDN.NET
- dubbo实践(二)自己动手编译源码
- alibaba/dubbo: Dubbo is a distributed, high performance RPC framework enpowering applications with service import/export capabilities.
- 2.5.4-SNAPSHOT dubbo admin error · Issue #50 · alibaba/dubbo
- code.alibabatech.com不能访问了,是阿里不让用了吗 · Issue #22 · alibaba/dubbo