在一個項目中用到netty-socketio碰到一個問題,有新手碰到這個問題可能會糾結(jié)不少時間,寫出來以供參考,有碰到類似問題的也可以節(jié)省點兒時間。。
在項目源碼編譯時報錯,錯誤截圖如下

Paste_Image.png
錯誤信息顯示 io.netty.util.internal.PlatformDependent
反編譯netty-transport-4.1.5.Final 的代碼可以看到
ChannelOutboundBuffer 里有一行代碼 如下
AtomicIntegerFieldUpdater unwritableUpdater = PlatformDependent.newAtomicIntegerFieldUpdater(ChannelOutboundBuffer.class, "unwritable");
PlatformDependent 是在netty-common-4.1.5.Final的包,同樣反編譯查看源碼,并沒有發(fā)現(xiàn)newAtomicLongFieldUpdater 這樣一個方法。
同樣4.1.5.final 的包竟然出現(xiàn)方法找不到的問題,這個不會是坑爹專用版吧???
找到netty-all-4.1.5.Final 看了下源碼 發(fā)現(xiàn) ChannelOutboundBuffer的實現(xiàn)已經(jīng)完全不一樣了。
索性把netty的分包的依賴全部替換掉, 修改maven的pom文件
<dependency>
<groupId>com.corundumstudio.socketio</groupId>
<artifactId>netty-socketio</artifactId>
<version>1.7.13</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transpor</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-resolver</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
</exclusion>
</exclusions>
</dependency>
自己引入netty-all的依賴
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.16.Final</version>
</dependency>
好了, 這樣就不會有問題了