mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-14 14:13:52 +08:00
Springboot 整合 Dubbo/ZooKeeper 详解 SOA 案例
This commit is contained in:
@@ -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