Dubbo 使用概念

https://blog.csdn.net/flashflight/article/details/43939275

简介

接入步骤

  1. 接口定义
  2. 接口实现,暴露接口
  3. 消息端引入服务,调用服务

接口定义

package com.test;
public interface DemoService{  
     String sayHello(String name);  
} 

生产者

接口实现

package com.test;
import org.springframework.stereotype.Service;

import com.test.DemoService;
@Service("demoService")
public class DemoServiceImpl implements DemoService{

    @Override
    public String sayHello(String name) {
        // TODO Auto-generated method stub
        return name; 
    }  
}

声明暴露服务




      
      

      
       

      
      

      
      

消费者

在xml文件中引入服务

    
          
        
           
          
             
          
        
 

调用服务

import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "classpath:springmvc.xml" });

        context.start();
        DemoService demoService = (DemoService) context.getBean("demoService");

        System.out.println(demoService.sayHello("哈哈哈"));
        try {
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

你可能感兴趣的:(Dubbo 使用概念)