admin 发表于 2016-8-11 16:44:55

【JEECG Dubbo专题】jeecg-p3集成dubbo文档

一、项目介绍

p3dubbo-service接口项目
p3dubbo-service-impl接口实现项目
jeecg-p3-webdubbo提供服务项目(服务端)
p3dubbo-consumerdubbo消费项目(客户端)

二、项目分解说明1 . p3dubbo-service说明:该项目为简单的maven构建项目,无任何依赖引用,只作接口定义   http://img.blog.csdn.net/20160811161240362?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center接口定义如下:http://img.blog.csdn.net/20160811162008436?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center    pom文件说明http://img.blog.csdn.net/20160811155520183?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center2. p3dubbo-service说明:该项目为接口实现项目,进行业务逻辑编写 http://img.blog.csdn.net/20160811155700793?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
接口实现如下:
@Service("demoService")
public class DemoServiceImpl implements DemoServiceI {

public String sayHello(String name) {
System.out.println(" -- jeecg-p3-dubbo---say: "+name);                  
return name + "";
   }
}
pom如下:(引入jeecg-p3父POM,增加dubbo依赖支持)
<parent>
    <groupId>org.p3framework</groupId>
    <artifactId>jeecg-p3-pom</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
<!-- 接口API -->
<dependency>
<groupId>org.p3dubbo</groupId>
<artifactId>p3dubbo-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

<!-- dubbo jar -->
<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>
<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>
      </dependencies>

Spring dubbo配置文件
<?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="jeecgp3_dubbo_provider"></dubbo:application>
   <!-- 使用zookeeper注册中心暴露服务地址 -->
   <dubbo:registry address="zookeeper://192.168.0.1:2181" check="false" subscribe="false" register=""></dubbo:registry>
   <!-- 要暴露的服务接口 -->
   <dubbo:service interface="com.jeecg.demo.DemoServiceI" ref="demoService" />

</beans>


3..jeecg-p3-web (启动项目)说明:该项目为jeecg-p3启动项目,作为服务提供项目,需要引入p3dubbo-service-impl项目1)引入spring dubbo配置   http://img.blog.csdn.net/20160811161404347?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center    2)pom引入接口实现项目    http://img.blog.csdn.net/20160811161451006?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center    启动项目jeecg-p3-web,提供服务(前台先按照zookeeper)4. p3dubbo-consumer(消费项目)    http://img.blog.csdn.net/20160811160205514?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center测试类:

public class DubboConsumer {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "applicationContext.xml" });         
context.start();

DemoServiceI demoService = (DemoServiceI) context.getBean("demoService");
String hello = demoService.sayHello("1998");
System.out.println(hello);
}
}



Spring 配置
<?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:application name="dubbo_consumer" />

    <!-- 使用zookeeper注册中心暴露服务地址 -->
    <dubbo:registry address="zookeeper://192.168.0.1:2181" />

    <!-- 生成远程服务代理,可以像使用本地bean一样使用demoService -->
    <dubbo:reference id="demoService"interface="com.jeecg.demo.DemoServiceI" />

</beans>


pom引用:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">               
<modelVersion>4.0.0</modelVersion>
<groupId>org.p3dubbo</groupId>
<artifactId>p3dubbo-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
<groupId>org.p3framework</groupId>
<artifactId>jeecg-p3-pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
<!-- api -->
<dependency>
<groupId>org.p3dubbo</groupId>
<artifactId>p3dubbo-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- dubbo jar -->
<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>
<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>
</dependencies>
</project>


测试结果.采用maven方式启动jeecg-p3-web项目      http://img.blog.csdn.net/20160811161540976?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Centerhttp://img.blog.csdn.net/20160811161610082?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
.执行类DubboConsumer 客户端: http://img.blog.csdn.net/20160811161647207?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center 服务端: http://img.blog.csdn.net/20160811161709254?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
    源码下载地址:http://pan.baidu.com/s/1b78fuu 密码:qtx3
页: [1]
查看完整版本: 【JEECG Dubbo专题】jeecg-p3集成dubbo文档