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:
51
springboot-dubbo-server/pom.xml
Executable file
51
springboot-dubbo-server/pom.xml
Executable file
@@ -0,0 +1,51 @@
|
||||
<?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-server</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,20 @@
|
||||
package org.spring.springboot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Spring Boot 应用启动类
|
||||
*
|
||||
* Created by bysocket on 16/4/26.
|
||||
*/
|
||||
// Spring Boot 应用的标识
|
||||
@SpringBootApplication
|
||||
public class ServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 程序启动入口
|
||||
// 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
|
||||
SpringApplication.run(ServerApplication.class,args);
|
||||
}
|
||||
}
|
||||
@@ -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 City() {
|
||||
}
|
||||
|
||||
public City(Long id, Long provinceId, String cityName, String description) {
|
||||
this.id = id;
|
||||
this.provinceId = provinceId;
|
||||
this.cityName = cityName;
|
||||
this.description = 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;
|
||||
}
|
||||
}
|
||||
@@ -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,20 @@
|
||||
package org.spring.springboot.dubbo.impl;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
import org.spring.springboot.domain.City;
|
||||
import org.spring.springboot.dubbo.CityDubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 城市业务 Dubbo 服务层实现层
|
||||
*
|
||||
* Created by bysocket on 28/02/2017.
|
||||
*/
|
||||
// 注册为 Dubbo 服务
|
||||
@Service(version = "1.0.0")
|
||||
public class CityDubboServiceImpl implements CityDubboService {
|
||||
|
||||
public City findCityByName(String cityName) {
|
||||
return new City(1L,2L,"温岭","是我的故乡");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
## Dubbo 服务提供者配置
|
||||
spring.dubbo.application.name=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.spring.springboot.dubbo
|
||||
Reference in New Issue
Block a user