springboot整合dubbo過程踩了很多坑,現在梳理一個正確的方式:
一. pom配置:dubbo相關的依賴都統一采用alibaba的,並且需要一個nio依賴
分別是:
1. dubbo本身的jar
2. dubbo和springboot整合的jar
3. springboot讀取dubbo配置的jar(我在做的時候一直報config讀取不到,ben找不到之類的錯誤,就是因為沒有這個jar)
4. nio
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba.boot/dubbo-spring-boot-starter -->
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.32.Final</version>
</dependency>
2. 在注冊服務的啟動類加@EnableDubbo
@EnableDubbo
@SpringBootApplication
@MapperScan(basePackages="com.csp.test.user.mapper")
public class UserServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UserServiceApplication.class, args);
}
}
Service聲明必須是dubbo的:
import com.alibaba.dubbo.config.annotation.Service;
@Service
public class UserServiceImpl implements UserService {
}
3. 配置dubbo連接屬性
# dubbo的配置 # dubbo中的服務名稱 #spring.dubbo.application=user-service dubbo.application.name=user-service # dubbo的通訊協議名稱 dubbo.protocol.name=dubbo #spring.dubbo.protocol.name=dubbo # zookeeper注冊中心的地址 dubbo.registry.address=192.168.15.136:2181 # zookeeper的通訊協議的名稱 dubbo.registry.protocol=zookeeper # dubbo的服務的掃描路徑 dubbo.scan.base-packages=com.csp.imall # 設置超時時間 dubbo.consumer.timeout=600000 # 設置是否檢查服務存在 dubbo.consumer.check=false
啟動成功后查看dubbo-admin:

注冊成功
