在Spring Boot应用程序中使用web3j java库时,在Web3j.build行中出现以下异常。有解决这个问题的主意吗?
私有静态最终Web3j web3j = Web3j.build(new HttpService(“ https://rinkeby.infura.io/v3/sdas”));
Caused by: java.lang.NoSuchFieldError: TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
at org.web3j.protocol.http.HttpService.<clinit>(HttpService.java:37)
at sg.com.paloit.hashit.service.ContractService.<clinit>(ContractService.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1147)
... 48 common frames omitted
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.1.0</version>
</dependency>
答案 0 :(得分:1)
org.web3j(4.1.0)内核随附没有密码的较低版本的okhttp:TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256。
它是一个相对较新的密码,将okhttp更改为okhttp3有助于解决此问题。
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.1.0</version>
<exclusions>
<exclusion>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.0</version>
</dependency>