- 背景
項目中同時使用了Redis和Netty,SpringBoot版本使用的2.1.6正式版;在Linux環境下運行Redis無法正常連接
資源引用如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.38.Final</version>
</dependency>
錯誤信息如下:
- 衝突
由於spring-boot-starter-data-redis中也引用了Netty,且和我自行引用的版本不一致,如下圖檢查
從上圖可以看出,使用的是
4.1.36.Final
的版本,但是上面我自己引入了一個4.1.38.Final
的版本,導致版本不一致 - 解決方式
將自己導入Netty的版本修改爲上圖中Redis關聯的相同版本(4.1.36.Final)即可
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.36.Final</version>
</dependency>
- 總結
Netty作爲一個優秀的框架,在很多三方庫中都會作爲基礎庫使用,如果版本不一致的話,就可能帶來衝突問題,因此統一版本會減少或者規避很多問題