Spring Boot整合Dubbo
0
安装ZooKeeper:
下载:http://archive.apache.org/dist/zookeeper/zookeeper-3.4.8/
启动:bin/zkServer
Dubbo管理项目:
dubbo-admin:https://github.com/apache/incubator-dubbo-ops
使用Maven打包后放入到Tomcat后启动Tomcat。
打包出现一下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project dubbo-admin: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] 错误: 不再支持源选项 5。请使用 6 或更高版本。
[ERROR] 错误: 不再支持目标选项 1.5。请使用 1.6 或更高版本。
[ERROR] -> [Help 1]
在pom里面添加:
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
如果使用Java9+的Tomcat版本需要更新到Apache Tomcat 8.0.48
以后才可以,不然启动不了。
升级Tomcat后发现还是不行,出现一下错误:
ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletC
ntext resource [/WEB-INF/webx.xml]; nested exception is java.lang.IllegalArgumentException: Unknown flag 0x1000
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.
ava:413)
这个应该是Java9以后模块化问题导致的,先换到Java8,不管这个问题。
Dubbo项目:
Maven依赖:
<!-- dubbo:http://dubbo.apache.org/books/dubbo-user-book/references/protocol/dubbo.html -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-config-spring</artifactId>
</dependency>
<!-- 注册中心 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry-zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-cluster</artifactId>
</dependency>
<!-- RPC协议 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-rpc-dubbo</artifactId>
</dependency>
<!-- 网络传输 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-serialization-hessian2</artifactId>
</dependency>
服务端配置:
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="${dubbo.application.name}" />
<!-- 注册中心暴露服务地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234" /> -->
<!-- <dubbo:registry protocol="zookeeper" address="10.170.219.98:2181,10.173.55.173:2181" /> -->
<dubbo:registry address="${dubbo.registry.address}" />
<!-- 暴露服务 -->
<dubbo:protocol name="${dubbo.protocol.name}" port="${dubbo.protocol.port}" />
<dubbo:service interface="com.acgist.service.IUserService" ref="userService" retries="0" timeout="6000" />
客户端配置:
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="${dubbo.application.name}" />
<!-- 注册中心暴露服务地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234" /> -->
<!-- <dubbo:registry protocol="zookeeper" address="10.170.219.98:2181,10.173.55.173:2181" /> -->
<dubbo:registry address="${dubbo.registry.address}" />
<!-- 暴露服务 -->
<!--
<dubbo:protocol name="${dubbo.protocol.name}" port="${dubbo.protocol.port}" />
-->
<dubbo:reference id="userService" interface="com.acgist.service.IUserService" check="false" />
完整项目:sbc-dubbo-common、sbc-dubbo-service、sbc-dubbo-consumer,地址:https://github.com/acgist/demo
启动后访问:http://localhost:9999/user/index
dubbo服务不能访问
查看dubbo服务注册时主机是否绑定了虚拟网卡
参考文章:
https://www.cnblogs.com/shengulong/p/8303454.html
https://blog.csdn.net/cl_andywin/article/details/54318903
https://blog.csdn.net/helloword_monkey/article/details/78939072
http://dubbo.apache.org/books/dubbo-user-book/references/protocol/dubbo.html