spring+dubbo整合

2016三月
30

spring+dubbo整合

                        <label><i class="fa fa-exclamation-triangle"></i><span onclick="javascript:report(51014320,2);return false;"> 举报</span></label>
                        <label><i class="fa fa-bookmark-o"></i><span onclick="javascript:collectArticle('spring+dubbo整合','51014320');return false;"> 收藏</span></label>
                         

                         
                      </p>
                    </div>
                  <div class="skin_detail" id="article_content">

创建公共接口或者工程用到的一些bean,我这里就只是创建了一个接口。工程目录如下:

DemoService接口的代码如下:

  1. <span style="font-size:14px;">package com.sw.www;  
  2.   
  3. public interface DemoService {  
  4.     public void sayHello();   
  5. }  
  6. </span>  


将上面的接口工程打包为一个jar给服务提供方和消费方公用,创建服务提供方工程,工程目录如下:

其中DemoServiceImpl实现了公共接口。而后期服务消费方不需要关心它是如何实现的。其代码如下:

  1. <span style="font-size:14px;">package com.sw.www.impl;  
  2.   
  3. import com.sw.www.DemoService;  
  4.   
  5. public class DemoServiceImpl implements DemoService{    
  6.     @Override    
  7.     public void sayHello() {    
  8.         System.out.println("hello dubbo!");    
  9.     }    
  10. }    
  11. </span>  


applicationProvider.xml 配置如下:

  1. <span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?>    
  2. <beans xmlns="http://www.springframework.org/schema/beans"    
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  4.     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"    
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans    
  6.         http://www.springframework.org/schema/beans/spring-beans.xsd    
  7.         http://code.alibabatech.com/schema/dubbo    
  8.         http://code.alibabatech.com/schema/dubbo/dubbo.xsd    
  9.         ">         
  10.     <dubbo:application name="hello-world-app" />         
  11.     <dubbo:registry  protocol="zookeeper" address="127.0.0.1:2181" />    
  12.     <dubbo:protocol name="dubbo" port="20880" />          
  13.     <bean id="demoService" class="com.sw.www.impl.DemoServiceImpl" />    
  14.     <!-- 和本地bean一样实现服务 -->    
  15.     <dubbo:service interface="com.sw.www.DemoService"  ref="demoService" />    
  16. </beans>   
  17. </span>  


pom.xml 配置如下:

  1. <span style="font-size:14px;"><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>com.sw.www</groupId>  
  5.     <artifactId>dubbo_provider</artifactId>  
  6.     <packaging>jar</packaging>  
  7.     <version>0.0.1-SNAPSHOT</version>  
  8.     <name>role_access_control</name>  
  9.     <url>http://maven.apache.org</url>  
  10.       
  11.     <!-- 各类依赖jar的版本声明 -->  
  12.     <properties>  
  13.         <junit.version>4.8.2</junit.version>  
  14.         <spring.version>3.2.2.RELEASE</spring.version>  
  15.         <javax-activation.version>1.1</javax-activation.version>  
  16.         <mysql-connector-java.version>5.1.34</mysql-connector-java.version>  
  17.         <shiro.version>1.2.3</shiro.version>  
  18.     </properties>  
  19.     <dependencies>  
  20.         <!-- junit -->  
  21.         <dependency>  
  22.             <groupId>junit</groupId>  
  23.             <artifactId>junit</artifactId>  
  24.             <version>${junit.version}</version>  
  25.             <type>jar</type>  
  26.         </dependency>  
  27.         <!-- spring start -->  
  28.         <dependency>  
  29.             <groupId>org.springframework</groupId>  
  30.             <artifactId>spring-aop</artifactId>  
  31.             <version>${spring.version}</version>  
  32.         </dependency>  
  33.         <dependency>  
  34.             <groupId>org.springframework</groupId>  
  35.             <artifactId>spring-aspects</artifactId>  
  36.             <version>${spring.version}</version>  
  37.         </dependency>  
  38.         <dependency>  
  39.             <groupId>org.springframework</groupId>  
  40.             <artifactId>spring-beans</artifactId>  
  41.             <version>${spring.version}</version>  
  42.         </dependency>  
  43.         <dependency>  
  44.             <groupId>org.springframework</groupId>  
  45.             <artifactId>spring-context</artifactId>  
  46.             <version>${spring.version}</version>  
  47.         </dependency>  
  48.         <dependency>  
  49.             <groupId>org.springframework</groupId>  
  50.             <artifactId>spring-context-support</artifactId>  
  51.             <version>${spring.version}</version>  
  52.         </dependency>  
  53.         <dependency>  
  54.             <groupId>org.springframework</groupId>  
  55.             <artifactId>spring-core</artifactId>  
  56.             <version>${spring.version}</version>  
  57.         </dependency>  
  58.         <dependency>  
  59.             <groupId>org.springframework</groupId>  
  60.             <artifactId>spring-dao</artifactId>  
  61.             <version>2.0.8</version>  
  62.         </dependency>  
  63.         <dependency>  
  64.             <groupId>org.springframework</groupId>  
  65.             <artifactId>spring-expression</artifactId>  
  66.             <version>${spring.version}</version>  
  67.         </dependency>  
  68.         <dependency>  
  69.             <groupId>org.springframework</groupId>  
  70.             <artifactId>spring-jdbc</artifactId>  
  71.             <version>${spring.version}</version>  
  72.         </dependency>  
  73.         <dependency>  
  74.             <groupId>org.springframework</groupId>  
  75.             <artifactId>spring-mock</artifactId>  
  76.             <version>2.0.8</version>  
  77.         </dependency>  
  78.         <dependency>  
  79.             <groupId>org.springframework</groupId>  
  80.             <artifactId>spring-orm</artifactId>  
  81.             <version>${spring.version}</version>  
  82.         </dependency>  
  83.         <dependency>  
  84.             <groupId>org.springframework</groupId>  
  85.             <artifactId>spring-test</artifactId>  
  86.             <version>${spring.version}</version>  
  87.         </dependency>  
  88.         <dependency>  
  89.             <groupId>org.springframework</groupId>  
  90.             <artifactId>spring-tx</artifactId>  
  91.             <version>${spring.version}</version>  
  92.         </dependency>  
  93.         <dependency>  
  94.             <groupId>org.springframework</groupId>  
  95.             <artifactId>spring-web</artifactId>  
  96.             <version>${spring.version}</version>  
  97.         </dependency>  
  98.         <dependency>  
  99.             <groupId>org.springframework</groupId>  
  100.             <artifactId>spring-webmvc</artifactId>  
  101.             <version>${spring.version}</version>  
  102.         </dependency>  
  103.         <!-- spring end -->  
  104.   
  105.         <!-- mysql -->  
  106.         <dependency>  
  107.             <groupId>mysql</groupId>  
  108.             <artifactId>mysql-connector-java</artifactId>  
  109.             <version>${mysql-connector-java.version}</version>  
  110.         </dependency>  
  111.   
  112.         <!-- shiro -->  
  113.         <dependency>  
  114.             <groupId>org.apache.shiro</groupId>  
  115.             <artifactId>shiro-core</artifactId>  
  116.             <version>${shiro.version}</version>  
  117.         </dependency>  
  118.         <dependency>  
  119.             <groupId>org.apache.shiro</groupId>  
  120.             <artifactId>shiro-web</artifactId>  
  121.             <version>${shiro.version}</version>  
  122.         </dependency>  
  123.         <dependency>  
  124.             <groupId>org.apache.shiro</groupId>  
  125.             <artifactId>shiro-spring</artifactId>  
  126.             <version>${shiro.version}</version>  
  127.         </dependency>  
  128.         <dependency>  
  129.             <groupId>org.apache.shiro</groupId>  
  130.             <artifactId>shiro-ehcache</artifactId>  
  131.             <version>${shiro.version}</version>  
  132.         </dependency>  
  133.         <dependency>  
  134.             <groupId>org.apache.shiro</groupId>  
  135.             <artifactId>shiro-quartz</artifactId>  
  136.             <version>${shiro.version}</version>  
  137.         </dependency>  
  138.   
  139.         <!-- servlet -->  
  140.         <dependency>  
  141.             <groupId>javax.servlet</groupId>  
  142.             <artifactId>servlet-api</artifactId>  
  143.             <version>2.5</version>  
  144.         </dependency>  
  145.         <dependency>  
  146.             <groupId>aopalliance</groupId>  
  147.             <artifactId>aopalliance</artifactId>  
  148.             <version>1.0</version>  
  149.         </dependency>  
  150.         <dependency>  
  151.             <groupId>org.apache.james</groupId>  
  152.             <artifactId>apache-mime4j</artifactId>  
  153.             <version>0.6.1</version>  
  154.         </dependency>  
  155.         <dependency>  
  156.             <groupId>asm</groupId>  
  157.             <artifactId>asm</artifactId>  
  158.             <version>3.3.1</version>  
  159.         </dependency>  
  160.         <dependency>  
  161.             <groupId>org.apache.axis</groupId>  
  162.             <artifactId>axis</artifactId>  
  163.             <version>1.4</version>  
  164.         </dependency>  
  165.         <dependency>  
  166.             <groupId>cglib</groupId>  
  167.             <artifactId>cglib-nodep</artifactId>  
  168.             <version>3.1</version>  
  169.         </dependency>  
  170.           
  171.         <!-- commons -->  
  172.         <dependency>  
  173.             <groupId>commons-beanutils</groupId>  
  174.             <artifactId>commons-beanutils</artifactId>  
  175.             <version>1.9.2</version>  
  176.         </dependency>  
  177.         <dependency>  
  178.             <groupId>commons-codec</groupId>  
  179.             <artifactId>commons-codec</artifactId>  
  180.             <version>1.10</version>  
  181.         </dependency>  
  182.         <dependency>  
  183.             <groupId>commons-collections</groupId>  
  184.             <artifactId>commons-collections</artifactId>  
  185.             <version>3.2.1</version>  
  186.         </dependency>  
  187.         <dependency>  
  188.             <groupId>commons-discovery</groupId>  
  189.             <artifactId>commons-discovery</artifactId>  
  190.             <version>0.5</version>  
  191.         </dependency>  
  192.         <dependency>  
  193.             <groupId>commons-fileupload</groupId>  
  194.             <artifactId>commons-fileupload</artifactId>  
  195.             <version>1.3.1</version>  
  196.         </dependency>  
  197.         <dependency>  
  198.             <groupId>commons-httpclient</groupId>  
  199.             <artifactId>commons-httpclient</artifactId>  
  200.             <version>3.1</version>  
  201.         </dependency>  
  202.         <dependency>  
  203.             <groupId>commons-io</groupId>  
  204.             <artifactId>commons-io</artifactId>  
  205.             <version>2.4</version>  
  206.         </dependency>  
  207.         <dependency>  
  208.             <groupId>commons-lang</groupId>  
  209.             <artifactId>commons-lang</artifactId>  
  210.             <version>2.6</version>  
  211.         </dependency>  
  212.         <dependency>  
  213.             <groupId>commons-logging</groupId>  
  214.             <artifactId>commons-logging</artifactId>  
  215.             <version>1.2</version>  
  216.         </dependency>  
  217.         <dependency>  
  218.             <groupId>dom4j</groupId>  
  219.             <artifactId>dom4j</artifactId>  
  220.             <version>1.6.1</version>  
  221.         </dependency>  
  222.           
  223.           
  224.         <dependency>  
  225.             <groupId>com.alibaba</groupId>  
  226.             <artifactId>druid</artifactId>  
  227.             <version>1.0.9</version>  
  228.         </dependency>  
  229.         <dependency>  
  230.             <groupId>net.sf.ehcache</groupId>  
  231.             <artifactId>ehcache-core</artifactId>  
  232.             <version>2.6.9</version>  
  233.         </dependency>  
  234.         <dependency>  
  235.             <groupId>net.sf.ezmorph</groupId>  
  236.             <artifactId>ezmorph</artifactId>  
  237.             <version>1.0.6</version>  
  238.         </dependency>  
  239.         <dependency>  
  240.             <groupId>org.freemarker</groupId>  
  241.             <artifactId>freemarker</artifactId>  
  242.             <version>2.3.21</version>  
  243.         </dependency>  
  244.         <dependency>  
  245.             <groupId>com.google.code.gson</groupId>  
  246.             <artifactId>gson</artifactId>  
  247.             <version>2.3.1</version>  
  248.         </dependency>  
  249.         <dependency>  
  250.             <groupId>org.apache.httpcomponents</groupId>  
  251.             <artifactId>httpcore</artifactId>  
  252.             <version>4.4</version>  
  253.         </dependency>  
  254.         <dependency>  
  255.             <groupId>org.apache.httpcomponents</groupId>  
  256.             <artifactId>httpmime</artifactId>  
  257.             <version>4.3.6</version>  
  258.         </dependency>  
  259.         <dependency>  
  260.             <groupId>com.fasterxml.jackson.core</groupId>  
  261.             <artifactId>jackson-core</artifactId>  
  262.             <version>2.4.4</version>  
  263.         </dependency>  
  264.         <dependency>  
  265.             <groupId>com.alibaba</groupId>  
  266.             <artifactId>fastjson</artifactId>  
  267.             <version>1.1.36</version>  
  268.         </dependency>  
  269.         <dependency>  
  270.             <groupId>javax.xml</groupId>  
  271.             <artifactId>jaxrpc</artifactId>  
  272.             <version>1.1</version>  
  273.         </dependency>  
  274.         <dependency>  
  275.             <groupId>jstl</groupId>  
  276.             <artifactId>jstl</artifactId>  
  277.             <version>1.2</version>  
  278.         </dependency>  
  279.         <dependency>  
  280.             <groupId>log4j</groupId>  
  281.             <artifactId>log4j</artifactId>  
  282.             <version>1.2.17</version>  
  283.         </dependency>  
  284.         <dependency>  
  285.             <groupId>org.mybatis</groupId>  
  286.             <artifactId>mybatis</artifactId>  
  287.             <version>3.2.1</version>  
  288.         </dependency>  
  289.         <dependency>  
  290.             <groupId>org.mybatis</groupId>  
  291.             <artifactId>mybatis-spring</artifactId>  
  292.             <version>1.2.0</version>  
  293.         </dependency>  
  294.         <dependency>  
  295.             <groupId>org.slf4j</groupId>  
  296.             <artifactId>slf4j-api</artifactId>  
  297.             <version>1.7.9</version>  
  298.         </dependency>  
  299.         <dependency>  
  300.             <groupId>org.slf4j</groupId>  
  301.             <artifactId>slf4j-log4j12</artifactId>  
  302.             <version>1.7.9</version>  
  303.         </dependency>  
  304.         <dependency>  
  305.             <groupId>taglibs</groupId>  
  306.             <artifactId>standard</artifactId>  
  307.             <version>1.1.2</version>  
  308.         </dependency>  
  309.         <dependency>  
  310.             <groupId>wsdl4j</groupId>  
  311.             <artifactId>wsdl4j</artifactId>  
  312.             <version>1.6.3</version>  
  313.         </dependency>  
  314.         <dependency>  
  315.             <groupId>org.freemarker</groupId>  
  316.             <artifactId>freemarker</artifactId>  
  317.             <version>2.3.21</version>  
  318.         </dependency>  
  319.         <!-- 后续 -->  
  320.           
  321.         <!-- dubbo依赖jar -->  
  322.         <dependency>  
  323.             <groupId>com.alibaba</groupId>  
  324.             <artifactId>dubbo</artifactId>  
  325.             <version>2.4.9</version>  
  326.             <exclusions>  
  327.                 <exclusion>  
  328.                     <artifactId>spring</artifactId>  
  329.                     <groupId>org.springframework</groupId>  
  330.                 </exclusion>  
  331.             </exclusions>  
  332.         </dependency>  
  333.   
  334.         <dependency>  
  335.             <groupId>org.apache.zookeeper</groupId>  
  336.             <artifactId>zookeeper</artifactId>  
  337.             <version>3.4.5</version>  
  338.             <exclusions>  
  339.                 <exclusion>  
  340.                     <groupId>log4j</groupId>  
  341.                     <artifactId>log4j</artifactId>  
  342.                 </exclusion>  
  343.             </exclusions>  
  344.         </dependency>  
  345.   
  346.         <dependency>  
  347.             <groupId>com.github.sgroschupf</groupId>  
  348.             <artifactId>zkclient</artifactId>  
  349.             <version>0.1</version>  
  350.         </dependency>  
  351.   
  352.     </dependencies>  
  353.     <build>  
  354.         <plugins>  
  355.             <plugin>  
  356.                 <artifactId>maven-compiler-plugin</artifactId>  
  357.                 <configuration>  
  358.                     <source>1.7</source>  
  359.                     <target>1.7</target>  
  360.                     <encoding>utf8</encoding>  
  361.                 </configuration>  
  362.             </plugin>  
  363.             <plugin>  
  364.                 <artifactId>maven-surefire-plugin</artifactId>  
  365.                 <configuration>  
  366.                     <includes>  
  367.                         <include>**/*Tests.java</include>  
  368.                     </includes>  
  369.                 </configuration>  
  370.             </plugin>  
  371.         </plugins>  
  372.         <defaultGoal>compile</defaultGoal>  
  373.         <finalName>dubbo_provider</finalName>  
  374.     </build>  
  375. </project>  
  376. </span>  

编写服务提供方启动的测试类TestProvider,代码如下:

  1. <span style="font-size:14px;">package com.sw.www;  
  2.   
  3. import org.springframework.context.ApplicationContext;  
  4. import org.springframework.context.support.ClassPathXmlApplicationContext;  
  5.   
  6. public class TestProvider {  
  7.     public static void main(String[] args) {  
  8.          try {  
  9.               // 初始化Spring  
  10.               ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationProvider.xml");  
  11.               System.out.println("dubbo provider is running...");   
  12.               System.in.read();  
  13.             } catch (Exception ex) {  
  14.               ex.printStackTrace();  
  15.             }  
  16.           }  
  17.     }</span>  





注意:因为我之前的工程是基于spring+springmvc+mybatis+shiro搭建的一个角色权限管理框架,所以一些相关的jar可以去掉(当然你不去掉也是没有问题的)。这里特别指出,后面的服务消费方的工程中的pom.xml和这个一样。记得导入公共接口的jar包。

创建服务消费方工程,工程目录如下:


消费方调用测试类TestDemo,代码如下:

  1. <span style="font-size:14px;">package com.sw.www;  
  2.   
  3. import java.io.IOException;  
  4.   
  5. import org.springframework.context.ApplicationContext;  
  6. import org.springframework.context.support.ClassPathXmlApplicationContext;  
  7.   
  8. public class TestDemo {  
  9.       
  10.     public static void main(String[] args) {  
  11.           
  12.         try {  
  13.             // 初始化Spring  
  14.             ApplicationContext ctx = new ClassPathXmlApplicationContext(  
  15.                     "applicationConsumer.xml");  
  16.             DemoService demoService = (DemoService) ctx  
  17.                     .getBean("demoService"); // 获取远程服务代理  
  18.             demoService.sayHello(); // 执行远程方法  
  19.             System.in.read();  
  20.             } catch (IOException e) {  
  21.                 e.printStackTrace();  
  22.             }  
  23.     }  
  24. }</span>  


applicationConsumer.xml 配置文件如下:

  1. <span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?>    
  2. <beans xmlns="http://www.springframework.org/schema/beans"    
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  4.     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"    
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans    
  6.         http://www.springframework.org/schema/beans/spring-beans.xsd    
  7.         http://code.alibabatech.com/schema/dubbo    
  8.         http://code.alibabatech.com/schema/dubbo/dubbo.xsd    
  9.         ">         
  10.     <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->    
  11.     <dubbo:application name="consumer-of-helloworld-app" />         
  12.     <!-- 使用multicast广播注册中心暴露发现服务地址 -->    
  13.     <dubbo:registry  protocol="zookeeper" address="127.0.0.1:2181"/>           
  14.     <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->    
  15.     <dubbo:reference id="demoService" interface="com.sw.www.DemoService" />    
  16. </beans> </span>  

pom.xml 配置如下:

  1. <span style="font-size:14px;"><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>com.sw.www</groupId>  
  5.     <artifactId>dubbo_consumer</artifactId>  
  6.     <packaging>jar</packaging>  
  7.     <version>0.0.1-SNAPSHOT</version>  
  8.     <name>role_access_control</name>  
  9.     <url>http://maven.apache.org</url>  
  10.       
  11.     <!-- 各类依赖jar的版本声明 -->  
  12.     <properties>  
  13.         <junit.version>4.8.2</junit.version>  
  14.         <spring.version>3.2.2.RELEASE</spring.version>  
  15.         <javax-activation.version>1.1</javax-activation.version>  
  16.         <mysql-connector-java.version>5.1.34</mysql-connector-java.version>  
  17.         <shiro.version>1.2.3</shiro.version>  
  18.     </properties>  
  19.     <dependencies>  
  20.         <!-- junit -->  
  21.         <dependency>  
  22.             <groupId>junit</groupId>  
  23.             <artifactId>junit</artifactId>  
  24.             <version>${junit.version}</version>  
  25.             <type>jar</type>  
  26.         </dependency>  
  27.         <!-- spring start -->  
  28.         <dependency>  
  29.             <groupId>org.springframework</groupId>  
  30.             <artifactId>spring-aop</artifactId>  
  31.             <version>${spring.version}</version>  
  32.         </dependency>  
  33.         <dependency>  
  34.             <groupId>org.springframework</groupId>  
  35.             <artifactId>spring-aspects</artifactId>  
  36.             <version>${spring.version}</version>  
  37.         </dependency>  
  38.         <dependency>  
  39.             <groupId>org.springframework</groupId>  
  40.             <artifactId>spring-beans</artifactId>  
  41.             <version>${spring.version}</version>  
  42.         </dependency>  
  43.         <dependency>  
  44.             <groupId>org.springframework</groupId>  
  45.             <artifactId>spring-context</artifactId>  
  46.             <version>${spring.version}</version>  
  47.         </dependency>  
  48.         <dependency>  
  49.             <groupId>org.springframework</groupId>  
  50.             <artifactId>spring-context-support</artifactId>  
  51.             <version>${spring.version}</version>  
  52.         </dependency>  
  53.         <dependency>  
  54.             <groupId>org.springframework</groupId>  
  55.             <artifactId>spring-core</artifactId>  
  56.             <version>${spring.version}</version>  
  57.         </dependency>  
  58.         <dependency>  
  59.             <groupId>org.springframework</groupId>  
  60.             <artifactId>spring-dao</artifactId>  
  61.             <version>2.0.8</version>  
  62.         </dependency>  
  63.         <dependency>  
  64.             <groupId>org.springframework</groupId>  
  65.             <artifactId>spring-expression</artifactId>  
  66.             <version>${spring.version}</version>  
  67.         </dependency>  
  68.         <dependency>  
  69.             <groupId>org.springframework</groupId>  
  70.             <artifactId>spring-jdbc</artifactId>  
  71.             <version>${spring.version}</version>  
  72.         </dependency>  
  73.         <dependency>  
  74.             <groupId>org.springframework</groupId>  
  75.             <artifactId>spring-mock</artifactId>  
  76.             <version>2.0.8</version>  
  77.         </dependency>  
  78.         <dependency>  
  79.             <groupId>org.springframework</groupId>  
  80.             <artifactId>spring-orm</artifactId>  
  81.             <version>${spring.version}</version>  
  82.         </dependency>  
  83.         <dependency>  
  84.             <groupId>org.springframework</groupId>  
  85.             <artifactId>spring-test</artifactId>  
  86.             <version>${spring.version}</version>  
  87.         </dependency>  
  88.         <dependency>  
  89.             <groupId>org.springframework</groupId>  
  90.             <artifactId>spring-tx</artifactId>  
  91.             <version>${spring.version}</version>  
  92.         </dependency>  
  93.         <dependency>  
  94.             <groupId>org.springframework</groupId>  
  95.             <artifactId>spring-web</artifactId>  
  96.             <version>${spring.version}</version>  
  97.         </dependency>  
  98.         <dependency>  
  99.             <groupId>org.springframework</groupId>  
  100.             <artifactId>spring-webmvc</artifactId>  
  101.             <version>${spring.version}</version>  
  102.         </dependency>  
  103.         <!-- spring end -->  
  104.   
  105.         <!-- mysql -->  
  106.         <dependency>  
  107.             <groupId>mysql</groupId>  
  108.             <artifactId>mysql-connector-java</artifactId>  
  109.             <version>${mysql-connector-java.version}</version>  
  110.         </dependency>  
  111.   
  112.         <!-- shiro -->  
  113.         <dependency>  
  114.             <groupId>org.apache.shiro</groupId>  
  115.             <artifactId>shiro-core</artifactId>  
  116.             <version>${shiro.version}</version>  
  117.         </dependency>  
  118.         <dependency>  
  119.             <groupId>org.apache.shiro</groupId>  
  120.             <artifactId>shiro-web</artifactId>  
  121.             <version>${shiro.version}</version>  
  122.         </dependency>  
  123.         <dependency>  
  124.             <groupId>org.apache.shiro</groupId>  
  125.             <artifactId>shiro-spring</artifactId>  
  126.             <version>${shiro.version}</version>  
  127.         </dependency>  
  128.         <dependency>  
  129.             <groupId>org.apache.shiro</groupId>  
  130.             <artifactId>shiro-ehcache</artifactId>  
  131.             <version>${shiro.version}</version>  
  132.         </dependency>  
  133.         <dependency>  
  134.             <groupId>org.apache.shiro</groupId>  
  135.             <artifactId>shiro-quartz</artifactId>  
  136.             <version>${shiro.version}</version>  
  137.         </dependency>  
  138.   
  139.         <!-- servlet -->  
  140.         <dependency>  
  141.             <groupId>javax.servlet</groupId>  
  142.             <artifactId>servlet-api</artifactId>  
  143.             <version>2.5</version>  
  144.         </dependency>  
  145.         <dependency>  
  146.             <groupId>aopalliance</groupId>  
  147.             <artifactId>aopalliance</artifactId>  
  148.             <version>1.0</version>  
  149.         </dependency>  
  150.         <dependency>  
  151.             <groupId>org.apache.james</groupId>  
  152.             <artifactId>apache-mime4j</artifactId>  
  153.             <version>0.6.1</version>  
  154.         </dependency>  
  155.         <dependency>  
  156.             <groupId>asm</groupId>  
  157.             <artifactId>asm</artifactId>  
  158.             <version>3.3.1</version>  
  159.         </dependency>  
  160.         <dependency>  
  161.             <groupId>org.apache.axis</groupId>  
  162.             <artifactId>axis</artifactId>  
  163.             <version>1.4</version>  
  164.         </dependency>  
  165.         <dependency>  
  166.             <groupId>cglib</groupId>  
  167.             <artifactId>cglib-nodep</artifactId>  
  168.             <version>3.1</version>  
  169.         </dependency>  
  170.           
  171.         <!-- commons -->  
  172.         <dependency>  
  173.             <groupId>commons-beanutils</groupId>  
  174.             <artifactId>commons-beanutils</artifactId>  
  175.             <version>1.9.2</version>  
  176.         </dependency>  
  177.         <dependency>  
  178.             <groupId>commons-codec</groupId>  
  179.             <artifactId>commons-codec</artifactId>  
  180.             <version>1.10</version>  
  181.         </dependency>  
  182.         <dependency>  
  183.             <groupId>commons-collections</groupId>  
  184.             <artifactId>commons-collections</artifactId>  
  185.             <version>3.2.1</version>  
  186.         </dependency>  
  187.         <dependency>  
  188.             <groupId>commons-discovery</groupId>  
  189.             <artifactId>commons-discovery</artifactId>  
  190.             <version>0.5</version>  
  191.         </dependency>  
  192.         <dependency>  
  193.             <groupId>commons-fileupload</groupId>  
  194.             <artifactId>commons-fileupload</artifactId>  
  195.             <version>1.3.1</version>  
  196.         </dependency>  
  197.         <dependency>  
  198.             <groupId>commons-httpclient</groupId>  
  199.             <artifactId>commons-httpclient</artifactId>  
  200.             <version>3.1</version>  
  201.         </dependency>  
  202.         <dependency>  
  203.             <groupId>commons-io</groupId>  
  204.             <artifactId>commons-io</artifactId>  
  205.             <version>2.4</version>  
  206.         </dependency>  
  207.         <dependency>  
  208.             <groupId>commons-lang</groupId>  
  209.             <artifactId>commons-lang</artifactId>  
  210.             <version>2.6</version>  
  211.         </dependency>  
  212.         <dependency>  
  213.             <groupId>commons-logging</groupId>  
  214.             <artifactId>commons-logging</artifactId>  
  215.             <version>1.2</version>  
  216.         </dependency>  
  217.         <dependency>  
  218.             <groupId>dom4j</groupId>  
  219.             <artifactId>dom4j</artifactId>  
  220.             <version>1.6.1</version>  
  221.         </dependency>  
  222.           
  223.           
  224.         <dependency>  
  225.             <groupId>com.alibaba</groupId>  
  226.             <artifactId>druid</artifactId>  
  227.             <version>1.0.9</version>  
  228.         </dependency>  
  229.         <dependency>  
  230.             <groupId>net.sf.ehcache</groupId>  
  231.             <artifactId>ehcache-core</artifactId>  
  232.             <version>2.6.9</version>  
  233.         </dependency>  
  234.         <dependency>  
  235.             <groupId>net.sf.ezmorph</groupId>  
  236.             <artifactId>ezmorph</artifactId>  
  237.             <version>1.0.6</version>  
  238.         </dependency>  
  239.         <dependency>  
  240.             <groupId>org.freemarker</groupId>  
  241.             <artifactId>freemarker</artifactId>  
  242.             <version>2.3.21</version>  
  243.         </dependency>  
  244.         <dependency>  
  245.             <groupId>com.google.code.gson</groupId>  
  246.             <artifactId>gson</artifactId>  
  247.             <version>2.3.1</version>  
  248.         </dependency>  
  249.         <dependency>  
  250.             <groupId>org.apache.httpcomponents</groupId>  
  251.             <artifactId>httpcore</artifactId>  
  252.             <version>4.4</version>  
  253.         </dependency>  
  254.         <dependency>  
  255.             <groupId>org.apache.httpcomponents</groupId>  
  256.             <artifactId>httpmime</artifactId>  
  257.             <version>4.3.6</version>  
  258.         </dependency>  
  259.         <dependency>  
  260.             <groupId>com.fasterxml.jackson.core</groupId>  
  261.             <artifactId>jackson-core</artifactId>  
  262.             <version>2.4.4</version>  
  263.         </dependency>  
  264.         <dependency>  
  265.             <groupId>com.alibaba</groupId>  
  266.             <artifactId>fastjson</artifactId>  
  267.             <version>1.1.36</version>  
  268.         </dependency>  
  269.         <dependency>  
  270.             <groupId>javax.xml</groupId>  
  271.             <artifactId>jaxrpc</artifactId>  
  272.             <version>1.1</version>  
  273.         </dependency>  
  274.         <dependency>  
  275.             <groupId>jstl</groupId>  
  276.             <artifactId>jstl</artifactId>  
  277.             <version>1.2</version>  
  278.         </dependency>  
  279.         <dependency>  
  280.             <groupId>log4j</groupId>  
  281.             <artifactId>log4j</artifactId>  
  282.             <version>1.2.17</version>  
  283.         </dependency>  
  284.         <dependency>  
  285.             <groupId>org.mybatis</groupId>  
  286.             <artifactId>mybatis</artifactId>  
  287.             <version>3.2.1</version>  
  288.         </dependency>  
  289.         <dependency>  
  290.             <groupId>org.mybatis</groupId>  
  291.             <artifactId>mybatis-spring</artifactId>  
  292.             <version>1.2.0</version>  
  293.         </dependency>  
  294.         <dependency>  
  295.             <groupId>org.slf4j</groupId>  
  296.             <artifactId>slf4j-api</artifactId>  
  297.             <version>1.7.9</version>  
  298.         </dependency>  
  299.         <dependency>  
  300.             <groupId>org.slf4j</groupId>  
  301.             <artifactId>slf4j-log4j12</artifactId>  
  302.             <version>1.7.9</version>  
  303.         </dependency>  
  304.         <dependency>  
  305.             <groupId>taglibs</groupId>  
  306.             <artifactId>standard</artifactId>  
  307.             <version>1.1.2</version>  
  308.         </dependency>  
  309.         <dependency>  
  310.             <groupId>wsdl4j</groupId>  
  311.             <artifactId>wsdl4j</artifactId>  
  312.             <version>1.6.3</version>  
  313.         </dependency>  
  314.         <dependency>  
  315.             <groupId>org.freemarker</groupId>  
  316.             <artifactId>freemarker</artifactId>  
  317.             <version>2.3.21</version>  
  318.         </dependency>  
  319.         <!-- 后续 -->  
  320.           
  321.         <!-- dubbo依赖jar -->  
  322.         <dependency>  
  323.             <groupId>com.alibaba</groupId>  
  324.             <artifactId>dubbo</artifactId>  
  325.             <version>2.4.9</version>  
  326.             <exclusions>  
  327.                 <exclusion>  
  328.                     <artifactId>spring</artifactId>  
  329.                     <groupId>org.springframework</groupId>  
  330.                 </exclusion>  
  331.             </exclusions>  
  332.         </dependency>  
  333.   
  334.         <dependency>  
  335.             <groupId>org.apache.zookeeper</groupId>  
  336.             <artifactId>zookeeper</artifactId>  
  337.             <version>3.4.5</version>  
  338.             <exclusions>  
  339.                 <exclusion>  
  340.                     <groupId>log4j</groupId>  
  341.                     <artifactId>log4j</artifactId>  
  342.                 </exclusion>  
  343.             </exclusions>  
  344.         </dependency>  
  345.   
  346.         <dependency>  
  347.             <groupId>com.github.sgroschupf</groupId>  
  348.             <artifactId>zkclient</artifactId>  
  349.             <version>0.1</version>  
  350.         </dependency>  
  351.   
  352.     </dependencies>  
  353.     <build>  
  354.         <plugins>  
  355.             <plugin>  
  356.                 <artifactId>maven-compiler-plugin</artifactId>  
  357.                 <configuration>  
  358.                     <source>1.7</source>  
  359.                     <target>1.7</target>  
  360.                     <encoding>utf8</encoding>  
  361.                 </configuration>  
  362.             </plugin>  
  363.             <plugin>  
  364.                 <artifactId>maven-surefire-plugin</artifactId>  
  365.                 <configuration>  
  366.                     <includes>  
  367.                         <include>**/*Tests.java</include>  
  368.                     </includes>  
  369.                 </configuration>  
  370.             </plugin>  
  371.         </plugins>  
  372.         <defaultGoal>compile</defaultGoal>  
  373.         <finalName>dubbo_consumer</finalName>  
  374.     </build>  
  375. </project>  
  376. </span>  


这个时候后我们的相关工程创建和代码的工作就完毕了。下面我们就来测试一把吧!

首先我们启动zk,然后我们启动dubbo-admin的管理界面,界面如下(这里就不讲述它的安装部署方法了可以参照相关的文章):


这里我们可以看到提供这里没有任何信息,下面我们来启动一下服务提供者,即上面提到的TestProvider类。运行完,我们可以看到管理页面如下:


上图我们就可以看到有服务的提供者信息了。但是此时我们还看不到消费者的信息,因为还没有消费者去调用这个服务:


这时我们就要启动消费服务的测试类,调用服务。即上面提到的TestDemo,调用完以后我们可以看到如下图:


到此整个过程就完毕了!

源码下载地址:http://download.csdn.net/detail/u011192409/9476829


                  </div>
                </dd>
              </dl>
posted @ 2017-01-19 17:38  jobs-lgy  阅读(1420)  评论(0编辑  收藏  举报