一、简介
昨天在网上发现了dubbo社区发布了Dubbo Spring Boot Starter 1.0.0 公测版, https://github.com/dubbo/dubbo-spring-boot-project 使用了springboot来开发,感觉应该很不错,然后就去试了下,发现dubbo-spring-boot-starter 底层依赖 Dubbo 2.5.9而2.5.9那个时候还没发布,今天再去github一看,竟然发布了,果断的下了个官方的demo: https://github.com/dubbo/dubbo-spring-boot-project/tree/master/dubbo-spring-boot-samples 下载下来之后,通过maven安装到本地:
在dubbo-spring-boot-project-master/dubbo-spring-boot-samples中的POM.XML由于引用了一个demo-api
<dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo-demo-api</artifactId> <version>${dubbo.version}</version> </dependency>
这个jar是在dubbo2.5.9中的
当时还特意提问了。。可以下载2.5.9的源码,然后本地构建安装就行了。
二、示例
直接可以导入官方的示例到IDEA中,运行看效果,我这边,自己根据官方的示例,写了个,主要感觉官方的demo依赖搞得有点多。。
父依赖:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.fendo.dubbo.demo</groupId> <artifactId>boot-dubbo-demo</artifactId> <packaging>pom</packaging> <version>1.0.0-SNAPSHOT</version> <parent> <artifactId>dubbo-spring-boot-parent</artifactId> <groupId>com.alibaba.boot</groupId> <version>1.0.0-SNAPSHOT</version> </parent> <modules> <module>dubbo-api</module> <module>dubbo-consumer</module> <module>dubbo-provider</module> </modules> <dependencies> </dependencies> </project>
生产端:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>boot-dubbo-demo</artifactId> <groupId>com.fendo.dubbo.demo</groupId> <version>1.0.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>dubbo-provider</artifactId> <packaging>jar</packaging> <name>dubbo-provider</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- Spring Boot dependencies --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator</artifactId> </dependency> <dependency> <groupId>com.fendo.dubbo.demo</groupId> <artifactId>dubbo-api</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> </dependencies> </project>
消费端:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>boot-dubbo-demo</artifactId> <groupId>com.fendo.dubbo.demo</groupId> <version>1.0.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>dubbo-consumer</artifactId> <packaging>jar</packaging> <name>dubbo-consumer</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- Spring Boot dependencies --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator</artifactId> </dependency> <dependency> <groupId>com.fendo.dubbo.demo</groupId> <artifactId>dubbo-api</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> </dependencies> </project>
先启动生产端,然后再启动消费端,访问localhost:xxx/sayHello?name=1212
github地址: https://github.com/fendo8888/boot-dubbo-demo