Dubbo第一个例程(Maven)

使用Maven创建项目

1、创建Dubbo Server

Dubbo第一个例程(Maven)_第1张图片
Dubbo第一个例程(Maven)_第2张图片

Dubbo第一个例程(Maven)_第3张图片
Dubbo第一个例程(Maven)_第4张图片

2、修改Dubbo Server的POM包依赖


  4.0.0

  com.test
  Proj_1604F_dubboProvider
  0.0.1-SNAPSHOT
  jar

  Proj_1604F_dubboProvider
  http://maven.apache.org

  
    UTF-8
  

	
	   
	      junit  
	      junit  
	      3.8.1  
	      test  
	      
			
			  commons-fileupload
			  commons-fileupload
			  1.3.2
			
	        
	          commons-logging  
	          commons-logging  
	          1.1.1  
	        
	        
	          com.alibaba  
	          dubbo  
	          2.5.8  
	        
	        
	          org.javassist  
	          javassist  
	          3.18.1-GA  
	        
	        
	          log4j  
	          log4j  
	          1.2.15  
	            
	                
	                  com.sun.jdmk  
	                  jmxtools  
	                
	                
	                  com.sun.jmx  
	                  jmxri  
	                
	                
	                  jms  
	                  javax.jms  
	                
	                
	                  mail  
	                  javax.mail  
	                
	            
	        
	        
	          org.springframework  
	          spring  
	          2.5.6.SEC03  
	        
	        
	          org.slf4j  
	          slf4j-api  
	          1.7.6  
	        
	        
	          org.slf4j  
	          slf4j-log4j12  
	          1.6.1  
	        
	        
	          org.apache.zookeeper  
	          zookeeper  
	          3.4.5  
	          pom  
	        
	        
	          com.101tec  
	          zkclient  
	          0.4  
	      
  



3、设计Spring配置文件

  
  
  
  
      
      
  
      
      
  
      
      
  
  
      
      
  

4、编写接口

package com.test;

public interface IOrderMng {
	public Integer saveOrder(String prdtName,Integer num,Integer price);
}

5、编写接口的实现类

package com.test;

public class OrderMng implements IOrderMng{

	public Integer saveOrder(String prdtName, Integer num, Integer price) {
		System.out.println("prdtName="+prdtName+",num="+num+",price="+price);
		
		return 100;
	}

}

6、编写测试类

package com.test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws Exception
    {
    	ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
    			new String[]{"provider.xml"});
    	ctx.start();
    	System.out.println("订单服务就绪...");
    	System.in.read();
    }
}

7、运行测试类App

Dubbo第一个例程(Maven)_第5张图片
Dubbo第一个例程(Maven)_第6张图片
Dubbo第一个例程(Maven)_第7张图片

8、创建Dubbo Client

POM


  4.0.0

  com.test
  Proj_1604F_dubboConsumer
  0.0.1-SNAPSHOT
  jar

  Proj_1604F_dubboConsumer
  http://maven.apache.org

  
    UTF-8
  

	
	   
	      junit  
	      junit  
	      3.8.1  
	      test  
	      
			
			  commons-fileupload
			  commons-fileupload
			  1.3.2
			
	        
	          commons-logging  
	          commons-logging  
	          1.1.1  
	        
	        
	          com.alibaba  
	          dubbo  
	          2.5.8  
	        
	        
	          org.javassist  
	          javassist  
	          3.18.1-GA  
	        
	        
	          log4j  
	          log4j  
	          1.2.15  
	            
	                
	                  com.sun.jdmk  
	                  jmxtools  
	                
	                
	                  com.sun.jmx  
	                  jmxri  
	                
	                
	                  jms  
	                  javax.jms  
	                
	                
	                  mail  
	                  javax.mail  
	                
	            
	        
	        
	          org.springframework  
	          spring  
	          2.5.6.SEC03  
	        
	        
	          org.slf4j  
	          slf4j-api  
	          1.7.6  
	        
	        
	          org.slf4j  
	          slf4j-log4j12  
	          1.6.1  
	        
	        
	          org.apache.zookeeper  
	          zookeeper  
	          3.4.5  
	          pom  
	        
	        
	          com.101tec  
	          zkclient  
	          0.4  
	      
  


9、配置Dubbo Client的Spring文件

  
  
  
  
      
      
  
      
      
  
      
      

  

10、编写Dubbo Client Java测试类

package com.test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{
        		"consumer.xml"
        });
        IOrderMng orderMng = (IOrderMng)ctx.getBean("orderMng");
        Integer no = orderMng.saveOrder("华为手机", 1, 2000);
        System.out.println("OrderNo="+no);
        
    }
}

你可能感兴趣的:(Dubbo)