Home

Awesome

#spring-boot-start-dubbo

Dubbo是阿里开发的一套分布式通讯框架,Spring-boot是业界比较火的微服务框架,两者可以进行结合实现分布式微服务

##如何发布Dubbo服务

 <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-dubbo</artifactId>
         <version>1.3.1.RELEASE</version>
 </dependency>
 <!--依赖于容器-->
 <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
         <version>1.3.1.RELEASE</version>
 </dependency>
spring.dubbo.application.name=annotation-provider
spring.dubbo.registry.address=zookeeper://127.0.0.1:2181
spring.dubbo.protocol.name=dubbo
spring.dubbo.protocol.port=20880
spring.dubbo.scan=org.mingyu.study

在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(Application.class);
        application.run(args);
    }
@Service(version = "1.0.0")
public class ServiceImpl implements ServiceA {

    @Override
    public String test() {
        return "hello";
    }
}

##如何引用Dubbo服务

 <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-dubbo</artifactId>
         <version>1.3.1.RELEASE</version>
 </dependency>
spring.dubbo.application.name=annotation-consumer
spring.dubbo.registry.address=zookeeper://127.0.0.1:2181
spring.dubbo.scan=com.lance

在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录

@SpringBootApplication
public class TestMain {
    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(Application.class);
        application.run(args);
    }
}
@Component
public class BarAction {

    @Reference(version = "1.0.0")
    private ServiceA fooService;
}

##关于spring-boot开发知识 <a href ="http://www.jianshu.com/users/aa6df7dd83ec/latest_articles">spring-boot学习笔记</a>