搭建spring+dubbo环境踩坑小记

spring+dubbo环境搭建网上汗牛充栋,但是实践过程中遇到种种麻烦,小记一篇,免得自己或者别人再次踩坑。 主要的问题是,项目需要引入哪些包,对有些版本过时的配置该如何修正,遇到异常如何处理(hello world应用代码极少,主要是配置问题)
参考文章Idea创建dubbo项目步骤和简单实例开发(dubo+zookeeper)
文章写的非常清楚,我们主要聚焦几个问题
1 dubboprovider 和 dubboconsumer的 pom配置

<!-- dubboprovider和dubbocomsumer 都需要引入,提供了dubbo注解,并会自动关联相应dubbo包,这里是2.6.2 -->
<dependency>
			<groupId>com.alibaba.boot</groupId>
			<artifactId>dubbo-spring-boot-starter</artifactId>
			<version>0.2.0</version>
</dependency>

<!-- dubboprovider和dubbocomsume spring web的启动器,不引入会遇到 4 那种问题 -->

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
</dependency>

只有dubboconsumer用到的包

<!-- Controller需要用到 @RequestMapping 等-->
<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
		</dependency>

2 dubboprovider 和 dubboconsumer的 application.properties文件配置
dubboprovider 相关配置

# apllication name
dubbo.application.name=dubboprovider

# register center
dubbo.registry.protocol=zookeeper
dubbo.registry.address=localhost:2181

dubbo.protocol.name=dubbo
dubbo.protocol.port=20880

dubbo.monitor.protocol=registry
#开启包扫描,因代码有 @EnableDubbo,所以不需要
#dubbo.scan.base-packages=com.dubbolearn.dubboprovider.service.impl

dubboconsumer需要的配置
server.port=7070

server.port=7070

# apllication name
dubbo.application.name=dubboconsumer

# register center
dubbo.registry.protocol=zookeeper
dubbo.registry.address=localhost:2181

#dubbo.protocol.name=dubbo
#dubbo.protocol.port=20880

dubbo.monitor.protocol=registry

3 启动文件配置

package com.dubbolearn.consumer;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
// 注意现在的写法需要改成这样
@EnableDubbo    
public class DubboconsumerApplication {

	public static void main(String[] args) {
		SpringApplication.run(DubboconsumerApplication.class, args);
	}

}

4 Current Spring Boot Application is await…的问题
启动dubboprovider 、 dubboconsumer 时,如果没有引入spring-boot-starter-web就会遇到该问题

5 Whitelabel Error Page…的问题
通过浏览器访问 localhost:7070/hello
如果遇到
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Jul 26 20:59:17 CST 2021
There was an unexpected error (type=Internal Server Error, status=500).

spring启动是成功的,但dubbo调用comsumer找不到provider
会在dubbocomsuer报错
检查 dubboprovider 的StudentServiceImpl的
@Service(interfaceClass = StudentService.class, version=“1.0.0”,timeout=15000)
和 dubboprovider的studentsController的

@Reference(interfaceClass = StudentService.class,version=“1.0.0”,check=false)
private StudentService studentService;
是否匹配一致
例如有没有这种错 https://www.cnblogs.com/wangchao928/p/15063380.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhyuli

您的鼓励是对我付出努力一种赞赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值