SpringBoot整合Dubbo
2021-04-09 20:26
标签:远程 host display list tle 一个 catch 关于 inf 入门级demo,并没有数据库之类的! 1、项目结构 一个empty project下有两个module: boot-user-service-provider(服务提供者) 和 boot-order-service-consumer(服务消费者) 至于怎么在一个空项目下创建多个module自己去百度 2、服务提供者 创建SpringBoot工程:boot-user-service-provider 1)依赖 【注意】坐标gmall-interface中包含了bean,和远程调用的接口,需要install进maven仓库中 2)启动类 3)服务提供者向zookeeper暴露的服务 4)application.yml : dubbo关于服务提供方的一些配置 3、服务消费者 1)依赖 2)启动类 3)控制器 controller和业务逻辑层 4)application.xml 4、依赖的工程 【注意】 要打成jar放入maven中 5、测试 启动两个工程 在浏览器访问:http://localhost:8085/initOrder?uid=1 成功 SpringBoot整合Dubbo 标签:远程 host display list tle 一个 catch 关于 inf 原文地址:https://www.cnblogs.com/houchen/p/13371625.htmlparent>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-parentartifactId>
version>2.0.1.RELEASEversion>
relativePath/>
parent>
dependencies>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starterartifactId>
dependency>
dependency>
groupId>com.atguigugroupId>
artifactId>gmall-interfaceartifactId>
version>1.0-SNAPSHOTversion>
dependency>
dependency>
groupId>com.alibaba.bootgroupId>
artifactId>dubbo-spring-boot-starterartifactId>
version>0.2.0version>
dependency>
dependencies>
@SpringBootApplication
@EnableDubbo //开启基于dubbo注解的开发
public class UserServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UserServiceApplication.class,args);
}
}
@Service //指出暴露的服务 【注意】这是dubbo的注解。引入包时别弄错
@Component
public class UserServiceImpl implements UserService {
public List
dubbo:
application:
name: user-service-provider
registry:
address: 172.20.10.14:2181
protocol: zookeeper
protocol:
name: dubbo
port: 20080
parent>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-parentartifactId>
version>2.0.1.RELEASEversion>
relativePath/>
parent>
dependencies>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-webartifactId>
dependency>
dependency>
groupId>com.atguigugroupId>
artifactId>gmall-interfaceartifactId>
version>1.0-SNAPSHOTversion>
dependency>
dependency>
groupId>com.alibaba.bootgroupId>
artifactId>dubbo-spring-boot-starterartifactId>
version>0.2.0version>
dependency>
dependencies>
@EnableDubbo
@SpringBootApplication
public class OrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class,args);
}
}
@Controller
public class OrderController {
@Autowired
private OrderService orderService;
@ResponseBody
@RequestMapping("/initOrder")
public List
dubbo:
application:
name: order-service-provider
registry:
address: 172.20.10.14:2181
protocol: zookeeper
server:
port: 8085
public class UserAddress implements Serializable {
private Integer id;
private String userAddress; //用户地址
private String userId; //用户id
private String consignee; //收货人
private String phoneNum; //电话号码
private String isDefault; //是否为默认地址 Y-是 N-否
public UserAddress() {
super();
// TODO Auto-generated constructor stub
}
public UserAddress(Integer id, String userAddress, String userId, String consignee, String phoneNum,
String isDefault) {
super();
this.id = id;
this.userAddress = userAddress;
this.userId = userId;
this.consignee = consignee;
this.phoneNum = phoneNum;
this.isDefault = isDefault;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserAddress() {
return userAddress;
}
public void setUserAddress(String userAddress) {
this.userAddress = userAddress;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getConsignee() {
return consignee;
}
public void setConsignee(String consignee) {
this.consignee = consignee;
}
public String getPhoneNum() {
return phoneNum;
}
public void setPhoneNum(String phoneNum) {
this.phoneNum = phoneNum;
}
public String getIsDefault() {
return isDefault;
}
public void setIsDefault(String isDefault) {
this.isDefault = isDefault;
}
}
public interface OrderService {
public List