- 通 maven 创建项目
- 创建一个父工程 mylongbang--pom : 管理所有子工程.
2.创建子工程分为俩种,一种是 jar 包工程和另一种 war 包工程;区别在于, jar 包工程是依赖于开发,而 war 包工程作将来部署的工程.
mylongbang-interface---jar ; mylongbang-dao ---jar ; mylongbang-common---jar
app ---war ; longwatch5s ---war ; lbvalidate --- war ; weichat ---war ; operate ---war
3.添加依赖 比如 : longwatch5s 依赖 mylongbang-interface---jar ; mylongbang-dao ---jar ; mylongbang-common---jar
4. mylongbang父工程pom.xml文件里添加dubbo 的 jar包坐标:
<!-- dubbo --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <artifactId>netty</artifactId> <groupId>org.jboss.netty</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency>
需要注意的是,javassist 这个包 3.18.1-GA 有问题,需要重新引入:
<dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.18.0-GA</version> </dependency>
包坐标加完以后,凡是war 项目报红,不要担心,做如下操作就解决
点击 Generate Deployment Descriptor Stub
然后 点击父工程 --> run --> maven install 这样,你的工程就可以在运行容器里 run 调试了!
5.配置 dubbo 注册服务和消费服务的 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/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd" > <!-- dubbo服务提供方配置 --> <!-- 配置应用的名称:用于监控 --> <dubbo:application name="test"></dubbo:application> <!-- 配置注册中心 --> <dubbo:registry protocol="zookeeper" address="192.168.191.3:2181"/> <!-- 配置dubbo直连 --> <!-- <dubbo:registry address="N/A"></dubbo:registry> <dubbo:protocol name="dubbo" port ="20880"></dubbo:protocol> --> <dubbo:service ref="dabboTestService" interface="com.lb.longwatch5s.services.DabboTestService"></dubbo:service> </beans>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 配置应用的名称:用于监控 --> <dubbo:application name="lbvalidate" /> <!-- 配置注册中心 --> <dubbo:registry protocol="zookeeper" address="192.168.191.3:2181" /> <!-- 配置dubbo直连 --> <!-- <dubbo:registry address="N/A"/> <dubbo:reference id="dabboTestService" interface="com.lb.longwatch5s.services.DabboTestService" url="dubbo://127.0.0.1:20880" /> --> <!-- 引用服务 --> <dubbo:reference id="dabboTestService" interface="com.lb.longwatch5s.services.DabboTestService" /> <!-- 全局连接超时时间 单位:毫秒 --> <dubbo:consumer timeout="60000000" /> </beans>
简单的 dubbo 就这样可以 run 了.
Tomcat 在 run 的时候 如有报错,请参考 http://www.cnblogs.com/bjxq-cs88/p/8573451.html 解决!