【初级教程】—Dubbo的配置及启动

  • Tomcat+Dubbo安装

        1.tomcatwebapps目录下的所有文件清空,讲Dubbo管理控制台的程序dubbo-admin-2.5.3.war

webapps中,并且解压命名为ROOT。

 

                 2.配置dubbo.properties

     将以下地址改为你Zookeeper注册的地址。前提:已经安装过Zookeeper。

                 dubbo.registry.address=zookeeper://192.168.137.2:2181

 

   3.启动tomcat

 

浏览:192.168.137.2:8080出现以下界面

【初级教程】—Dubbo的配置及启动_第1张图片

相应的配置已经配置好了,接下来开始写代码,看一下dubbo是怎么样在Zookeeper上注册服务的,在此举一个provider的例子:

 


建立一个maven项目,名称:Interfaces

 

建立一个类:


 package com.demo.rpc;
 
 public interface SpeakInterface
 {
        String speak(People people);
 }

再建一个maven项目,名称:provider

 

pom文件:

 

注意:这里在pom文件中引用interface

  


    4.0.0
 
    com.demo.dubbo
    dubbo-provider
    1.0-SNAPSHOT
 
    
        
            com.alibaba
            dubbo
            2.4.10
            
                
                    org.springframework
                    spring
                
            
        
        
            com.101tec
            zkclient
            0.4
        
        
            org.springframework
            spring-context
            3.2.8.RELEASE
        
        
            org.springframework
            spring-core
            3.2.8.RELEASE
        
        
            org.springframework
            spring-beans
            3.2.8.RELEASE
        
        
            com.jikexueyuan.rpc
            http-interfaces
            1.0.0-SNAPSHOT
        
        
            junit
            junit
            4.12
            test
        
        
            org.springframework
            spring-test
            3.2.8.RELEASE
            test
        
             
    org.apache.zookeeper
    zookeeper
    3.3.2
     
     
     
    
     
        
             
        
        
            org.apache.maven.plugins
            maven-jar-plugin
            
                target/classes/

        
                                   com.alibaba.dubbo.container.Main
    
                        false
        true
                        lib/
    
        
            .
        
                
            
        
        
    org.apache.maven.plugins
        maven-dependency-plugin
            
                
                    copy-dependencies
                    package
                    
                        copy-dependencies
                    
                    
                        jar
                        jar
                        
                            ${project.build.directory}/lib
                        
                    
                
            
        
    
   


src/main/resources路径下建立META-INF/spring文件夹,建立以下文件

 

Spring-context.xml文件



 
 
     
 
    
 


Spring-dubbo-provider.xml文件


 
    
 
    
 
    
 
    

    
 
    
 

SpeakInterfaceImpl类

import com.demo.rpc.GrowUpInterface;
import com.demo.rpc.People;
import com.demo.rpc.SpeakInterface;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * 2015/11/8
 */
@Component("speakInterface")
public class SpeakInterfaceImpl implements SpeakInterface {
  /*  @Resource
    private GrowUpInterface growUpInterface;*/
 
    public String speak(People people) {
        return "dubbo return ";
    }
}

启动,出现如下界面,说明服务已经注册上

【初级教程】—Dubbo的配置及启动_第2张图片

 

你可能感兴趣的:(【初级教程】—Dubbo的配置及启动)