FISCO-BCOS / web3sdk

java sdk for FISCO BCOS(deprecated, please use FISCO-BCOS/java-sdk)
Apache License 2.0
117 stars 86 forks source link

java.lang.NoSuchFieldError: SSL_MODE_ENABLE_FALSE_START #711

Open ywy2090 opened 4 years ago

ywy2090 commented 4 years ago

web3sdk 2.6.1启动时出现如下错误:

java.lang.NoSuchFieldError: SSL_MODE_ENABLE_FALSE_START at io.netty.handler.ssl.ReferenceCountedOpenSslEngine.(ReferenceCountedOpenSslEngine.java:355) ~[netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.handler.ssl.OpenSslEngine.(OpenSslEngine.java:32) ~[netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.handler.ssl.OpenSslContext.newEngine0(OpenSslContext.java:49) ~[netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.handler.ssl.ReferenceCountedOpenSslContext.newHandler(ReferenceCountedOpenSslContext.java:389) ~[netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.handler.ssl.SslContext.newHandler(SslContext.java:945) ~[netty-all-4.1.52.Final.jar:4.1.52.Final] at org.fisco.bcos.channel.handler.ChannelConnections$1.initChannel(ChannelConnections.java:396) ~[web3sdk-2.6.1.jar:na] at org.fisco.bcos.channel.handler.ChannelConnections$1.initChannel(ChannelConnections.java:386) ~[web3sdk-2.6.1.jar:na] at io.netty.channel.ChannelInitializer.initChannel(ChannelInitializer.java:129) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.ChannelInitializer.handlerAdded(ChannelInitializer.java:112) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.AbstractChannelHandlerContext.callHandlerAdded(AbstractChannelHandlerContext.java:938) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.DefaultChannelPipeline.callHandlerAdded0(DefaultChannelPipeline.java:609) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.DefaultChannelPipeline.access$100(DefaultChannelPipeline.java:46) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.DefaultChannelPipeline$PendingHandlerAddedTask.execute(DefaultChannelPipeline.java:1463) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.DefaultChannelPipeline.callHandlerAddedForAllHandlers(DefaultChannelPipeline.java:1115) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.DefaultChannelPipeline.invokeHandlerAddedIfNeeded(DefaultChannelPipeline.java:650) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:502) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:417) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:474) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:164) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-all-4.1.52.Final.jar:4.1.52.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-all-4.1.52.Final.jar:4.1.52.Final] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_231]

ywy2090 commented 4 years ago

原因: netty-all-4.1.52 版本做了升级,使用了较高版本的tcnative的内部变量,导致NoSuchFieldError异常,web3sdk无法初始化成功

解决方法,下面两种解决方案任选其一即可:

  1. 使用netty<=4.1.51的版本

  2. 使用web3sdk<=2.5.1的版本,并且添加下列依赖:

    compile 'io.netty:netty-tcnative:2.0.27.Final'
    compile 'io.netty:netty-tcnative-boringssl-static:2.0.27.Final'
foxyll commented 4 years ago

我使用第1种方法,web3sdk版本2.6.1,netty-all:4.1.9.Final版本,web3sdk启动报如下错误:

java.lang.IllegalStateException: Failed to load ApplicationContext

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:123)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getWeb3j' defined in class path resource [fisco/test2/demo/autoconfigure/Web3jConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.fisco.bcos.web3j.protocol.Web3j]: Factory method 'getWeb3j' threw exception; nested exception is java.lang.UnsatisfiedLinkError: failed to load the required native library at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ... 24 more Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.fisco.bcos.web3j.protocol.Web3j]: Factory method 'getWeb3j' threw exception; nested exception is java.lang.UnsatisfiedLinkError: failed to load the required native library at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ... 43 more Caused by: java.lang.UnsatisfiedLinkError: failed to load the required native library at io.netty.handler.ssl.OpenSsl.ensureAvailability(OpenSsl.java:292) at io.netty.handler.ssl.ReferenceCountedOpenSslContext.(ReferenceCountedOpenSslContext.java:228) at io.netty.handler.ssl.ReferenceCountedOpenSslContext.(ReferenceCountedOpenSslContext.java:217) at io.netty.handler.ssl.OpenSslContext.(OpenSslContext.java:34) at io.netty.handler.ssl.OpenSslClientContext.(OpenSslClientContext.java:187) at io.netty.handler.ssl.SslContext.newClientContextInternal(SslContext.java:755) at io.netty.handler.ssl.SslContextBuilder.build(SslContextBuilder.java:418) at org.fisco.bcos.channel.handler.ChannelConnections.initSslContext(ChannelConnections.java:626) at org.fisco.bcos.channel.handler.ChannelConnections.startConnect(ChannelConnections.java:381) at org.fisco.bcos.channel.client.Service.run(Service.java:335) at fisco.test2.demo.autoconfigure.Web3jConfig.getWeb3j(Web3jConfig.java:31) at fisco.test2.demo.autoconfigure.Web3jConfig$$EnhancerBySpringCGLIB$$7af2cccf.CGLIB$getWeb3j$0() at fisco.test2.demo.autoconfigure.Web3jConfig$$EnhancerBySpringCGLIB$$7af2cccf$$FastClassBySpringCGLIB$$59c3227.invoke() at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) at fisco.test2.demo.autoconfigure.Web3jConfig$$EnhancerBySpringCGLIB$$7af2cccf.getWeb3j() at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 44 more Caused by: java.lang.IllegalArgumentException: Failed to load any of the given libraries: [netty-tcnative-windows-x86_64, netty-tcnative] at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:178) at io.netty.handler.ssl.OpenSsl.loadTcNative(OpenSsl.java:384) at io.netty.handler.ssl.OpenSsl.(OpenSsl.java:84) ... 64 more

使用第2种方法,web3sdk版本改成2.5.1,就不会报异常