我一直在使用IntelliJ 2017.01 Ultimate和gradle来使用GRPC for IPC开发Java应用程序一段时间了。最近,我发现当我通过IntelliJ运行配置启动应用程序时,我收到以下错误:
io.grpc.netty.NettyServerHandler onHeadersRead
WARNING: Exception in onHeadersRead()
java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.createUnstarted()Lcom/google/common/base/Stopwatch;
at io.grpc.internal.GrpcUtil$3.get(GrpcUtil.java:490)
at io.grpc.internal.GrpcUtil$3.get(GrpcUtil.java:487)
at io.grpc.internal.StatsTraceContext.<init>(StatsTraceContext.java:92)
at io.grpc.internal.StatsTraceContext.newClientContext(StatsTraceContext.java:106)
at io.grpc.internal.StatsTraceContext.<clinit>(StatsTraceContext.java:64)
at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.methodDetermined(ServerImpl.java:387)
at io.grpc.netty.NettyServerHandler.onHeadersRead(NettyServerHandler.java:196)
at io.grpc.netty.NettyServerHandler.access$300(NettyServerHandler.java:90)
at io.grpc.netty.NettyServerHandler$FrameListener.onHeadersRead(NettyServerHandler.java:474)
at io.grpc.netty.FixedHttp2ConnectionDecoder$FrameReadListener.onHeadersRead(FixedHttp2ConnectionDecoder.java:320)
at io.netty.handler.codec.http2.Http2InboundFrameLogger$1.onHeadersRead(Http2InboundFrameLogger.java:65)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader$1.processFragment(DefaultHttp2FrameReader.java:461)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readHeadersFrame(DefaultHttp2FrameReader.java:468)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.processPayloadState(DefaultHttp2FrameReader.java:253)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readFrame(DefaultHttp2FrameReader.java:160)
at io.netty.handler.codec.http2.Http2InboundFrameLogger.readFrame(Http2InboundFrameLogger.java:41)
at io.grpc.netty.FixedHttp2ConnectionDecoder.decodeFrame(FixedHttp2ConnectionDecoder.java:119)
at io.netty.handler.codec.http2.Http2ConnectionHandler$FrameDecoder.decode(Http2ConnectionHandler.java:341)
at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:401)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:411)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:642)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:565)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:479)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:441)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:745)
接着是
io.grpc.netty.NettyServerHandler onStreamError
WARNING: Stream Error
io.netty.handler.codec.http2.Http2Exception$StreamException: com.google.common.base.Stopwatch.createUnstarted()Lcom/google/common/base/Stopwatch;
at io.netty.handler.codec.http2.Http2Exception.streamError(Http2Exception.java:147)
at io.grpc.netty.NettyServerHandler.newStreamException(NettyServerHandler.java:452)
at io.grpc.netty.NettyServerHandler.onHeadersRead(NettyServerHandler.java:211)
at io.grpc.netty.NettyServerHandler.access$300(NettyServerHandler.java:90)
at io.grpc.netty.NettyServerHandler$FrameListener.onHeadersRead(NettyServerHandler.java:474)
at io.grpc.netty.FixedHttp2ConnectionDecoder$FrameReadListener.onHeadersRead(FixedHttp2ConnectionDecoder.java:320)
at io.netty.handler.codec.http2.Http2InboundFrameLogger$1.onHeadersRead(Http2InboundFrameLogger.java:65)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader$1.processFragment(DefaultHttp2FrameReader.java:461)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readHeadersFrame(DefaultHttp2FrameReader.java:468)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.processPayloadState(DefaultHttp2FrameReader.java:253)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readFrame(DefaultHttp2FrameReader.java:160)
at io.netty.handler.codec.http2.Http2InboundFrameLogger.readFrame(Http2InboundFrameLogger.java:41)
at io.grpc.netty.FixedHttp2ConnectionDecoder.decodeFrame(FixedHttp2ConnectionDecoder.java:119)
at io.netty.handler.codec.http2.Http2ConnectionHandler$FrameDecoder.decode(Http2ConnectionHandler.java:341)
at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:401)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:411)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:642)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:565)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:479)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:441)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.createUnstarted()Lcom/google/common/base/Stopwatch;
at io.grpc.internal.GrpcUtil$3.get(GrpcUtil.java:490)
at io.grpc.internal.GrpcUtil$3.get(GrpcUtil.java:487)
at io.grpc.internal.StatsTraceContext.<init>(StatsTraceContext.java:92)
at io.grpc.internal.StatsTraceContext.newClientContext(StatsTraceContext.java:106)
at io.grpc.internal.StatsTraceContext.<clinit>(StatsTraceContext.java:64)
at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.methodDetermined(ServerImpl.java:387)
at io.grpc.netty.NettyServerHandler.onHeadersRead(NettyServerHandler.java:196)
... 29 more
一旦我从命令行运行应用程序,我就不会收到任何这些错误。我想这是guava和IntelliJ设置的类路径的问题,但我不知道如何解决这个问题。
我的build.gradle包含:
dependencies {
compile project(':synthesis')
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'org.json', name: 'json', version: '20160810'
compile group: 'net.java.dev.jna', name: 'jna', version: '4.3.0'
//compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile 'io.grpc:grpc-netty:1.2.0'
compile 'io.grpc:grpc-protobuf:1.2.0'
compile 'io.grpc:grpc-stub:1.2.0'
}
答案 0 :(得分:1)
com.google.common.base.Stopwatch.createUnstarted()
自Guava 15以来就存在了。看起来你正在使用旧版本。尝试运行./gradlew dependencies
以查看旧版本的来源。
我希望你得到guava-jdk5
的依赖(而不是对guava
的旧依赖)。你可以exclude the dependency:
dependencies {
all*.exclude group: 'com.google.guava', module: 'guava-jdk5'
}