mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-13 21:43:45 +08:00
Springboot 整合 Dubbo/ZooKeeper 详解 SOA 案例
This commit is contained in:
52
springboot-dubbo-client/pom.xml
Executable file
52
springboot-dubbo-client/pom.xml
Executable file
@@ -0,0 +1,52 @@
|
||||
<?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>springboot</groupId>
|
||||
<artifactId>springboot-dubbo-client</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>springboot-dubbo 客户端:: 整合 Dubbo/ZooKeeper 详解 SOA 案例</name>
|
||||
|
||||
<!-- Spring Boot 启动父依赖 -->
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.5.1.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<dubbo-spring-boot>1.0.0</dubbo-spring-boot>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spring Boot Dubbo 依赖 -->
|
||||
<dependency>
|
||||
<groupId>io.dubbo.springboot</groupId>
|
||||
<artifactId>spring-boot-starter-dubbo</artifactId>
|
||||
<version>${dubbo-spring-boot}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Web 依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Test 依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.spring.springboot;
|
||||
|
||||
import org.spring.springboot.dubbo.CityDubboConsumerService;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
/**
|
||||
* Spring Boot 应用启动类
|
||||
*
|
||||
* Created by bysocket on 16/4/26.
|
||||
*/
|
||||
// Spring Boot 应用的标识
|
||||
@SpringBootApplication
|
||||
public class ClientApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 程序启动入口
|
||||
// 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
|
||||
ConfigurableApplicationContext run = SpringApplication.run(ClientApplication.class, args);
|
||||
CityDubboConsumerService cityService = run.getBean(CityDubboConsumerService.class);
|
||||
cityService.printCity();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.spring.springboot.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 城市实体类
|
||||
*
|
||||
* Created by bysocket on 07/02/2017.
|
||||
*/
|
||||
public class City implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
/**
|
||||
* 城市编号
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 省份编号
|
||||
*/
|
||||
private Long provinceId;
|
||||
|
||||
/**
|
||||
* 城市名称
|
||||
*/
|
||||
private String cityName;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getProvinceId() {
|
||||
return provinceId;
|
||||
}
|
||||
|
||||
public void setProvinceId(Long provinceId) {
|
||||
this.provinceId = provinceId;
|
||||
}
|
||||
|
||||
public String getCityName() {
|
||||
return cityName;
|
||||
}
|
||||
|
||||
public void setCityName(String cityName) {
|
||||
this.cityName = cityName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "City{" +
|
||||
"id=" + id +
|
||||
", provinceId=" + provinceId +
|
||||
", cityName='" + cityName + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.spring.springboot.dubbo;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import org.spring.springboot.domain.City;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 城市 Dubbo 服务消费者
|
||||
*
|
||||
* Created by bysocket on 28/02/2017.
|
||||
*/
|
||||
@Component
|
||||
public class CityDubboConsumerService {
|
||||
|
||||
@Reference(version = "1.0.0")
|
||||
CityDubboService cityDubboService;
|
||||
|
||||
public void printCity() {
|
||||
String cityName="温岭";
|
||||
City city = cityDubboService.findCityByName(cityName);
|
||||
System.out.println(city.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.spring.springboot.dubbo;
|
||||
|
||||
import org.spring.springboot.domain.City;
|
||||
|
||||
/**
|
||||
* 城市业务 Dubbo 服务层
|
||||
*
|
||||
* Created by bysocket on 28/02/2017.
|
||||
*/
|
||||
public interface CityDubboService {
|
||||
|
||||
/**
|
||||
* 根据城市名称,查询城市信息
|
||||
* @param cityName
|
||||
*/
|
||||
City findCityByName(String cityName);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
## 避免和 server 工程端口冲突
|
||||
server.port=8081
|
||||
|
||||
## Dubbo 服务消费者配置
|
||||
spring.dubbo.application.name=consumer
|
||||
spring.dubbo.registry.address=zookeeper://127.0.0.1:2181
|
||||
spring.dubbo.scan=org.spring.springboot.dubbo
|
||||
Reference in New Issue
Block a user