java使用web3j开发代币转账遇到的一个错误

web3j 专栏收录该内容
1 篇文章 0 订阅

java使用web3j开发代币转账遇到的一个错误

最近在使用web3j开发代币转账,结果是一步一个坑爬过来。

/**
 * 新建钱包文件keyfile
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 * @throws InvalidAlgorithmParameterException
 * @throws CipherException
 * @throws IOException
 */
private static void creatAccount() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, CipherException, IOException {
    String walletFileName0="";//文件名
    String walletFilePath0="C:/temp/";
    //钱包文件保持路径,请替换位自己的某文件夹路径

    walletFileName0 = WalletUtils.generateNewWalletFile("123456", new File(walletFilePath0), false);
    System.out.println("walletName: "+walletFileName0);
}


/**
 * 加载钱包文件
 * @throws IOException
 * @throws CipherException
 */
public static void loadWallet() throws IOException, CipherException {
    String walleFilePath="C:/temp/UTC--2019-03-16T14-46-47.160000000Z--bbdd7c6b983f05f451e83e177c59894f076d008a.json";
    String passWord="123456";
    Credentials credentials = WalletUtils.loadCredentials(passWord, walleFilePath);
    String address = credentials.getAddress();
    BigInteger publicKey = credentials.getEcKeyPair().getPublicKey();
    BigInteger privateKey = credentials.getEcKeyPair().getPrivateKey();

    System.out.println("address="+address);
    System.out.println("public key="+publicKey);
    System.out.println("private key="+privateKey);

}

/**
 * 连接以太坊客户端
 * @throws IOException
 */
public static void conectETHclient() throws IOException {
    //连接方式1:使用infura 提供的客户端
    Web3j web3j = Web3j.build(new HttpService("https://rinkeby.infura.io/zmd7VgRt9go0x6qlJ2Mk"));// TODO: 2018/4/10 token更改为自己的
    //连接方式2:使用本地客户端
    //web3j = Web3j.build(new HttpService("127.0.0.1:7545"));
    //测试是否连接成功
    String web3ClientVersion = web3j.web3ClientVersion().send().getWeb3ClientVersion();
    System.out.println("version=" + web3ClientVersion);
}

/**
 * 查询账户余额
 * @throws IOException
 */
public static void getBlanceOf(String mainHttp, String address) throws IOException {
    Web3j web3j = Web3j.build(new HttpService(mainHttp));// TODO: 2018/4/10 token更改为自己的
    if (web3j == null) return;
    //第二个参数:区块的参数,建议选最新区块
    EthGetBalance balance = web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST).send();
    //格式转化 wei-ether
    String blanceETH = Convert.fromWei(balance.getBalance().toString(), Convert.Unit.ETHER).toPlainString().concat(" ether");
    System.out.println(blanceETH);
}


 /**
 * 交易ETH
 */
private static void transto() throws Exception {
    Web3j web3j = Web3j.build(new HttpService("https://mainnet.infura.io/v3/5643303661bc44fea37345d17703180f"));// TODO: 2018/4/10 token更改为自己的
    String walleFilePath="C:/temp/UTC--2019-03-16T14-46-47.160000000Z--bbdd7c6b983f05f451e83e177c59894f076d008a.json";
    String passWord="123456";
    Credentials credentials = WalletUtils.loadCredentials(passWord, walleFilePath);

    if (web3j == null) return;
    if (credentials == null) return;
    //开始发送0.01 =eth到指定地址
    String address_to = "0x091efcf34d6df5dcbd4cb8a6a05771bc81490619";
    TransactionReceipt send = Transfer.sendFunds(web3j, credentials, address_to, new BigDecimal("0.001"), Convert.Unit.ETHER).send();

    System.out.println("Transaction complete:");
    System.out.println("trans hash=" + send.getTransactionHash());
    System.out.println("from :" + send.getFrom());
    System.out.println("to:" + send.getTo());
    System.out.println("gas used=" + send.getGasUsed());
    System.out.println("status: " + send.getStatus());
}

以上代码我不记得是借用哪位大神的。网上很少找到交易其他代币的代码,之前有大神提过其他代币转账的时候gas费用有两种,一种是直接将用户的代币转换一部分ETH出来。还有一种就比较简单就是gas费用由平台负责,这里写下由平台负责的那种。

在这里插入图片描述

/**
* 代币交易
* @throws IOException
* @throws CipherException
* @throws ExecutionException
* @throws InterruptedException
*/

public static void transfer() throws IOException, CipherException, ExecutionException, InterruptedException {
	Web3j web3j = Web3j.build(new HttpService("可以去infura.io上创建一个项目获得主网地址,如上图"));
	Credentials credentials = WalletUtils.loadCredentials("交易密码", "创建钱包地址时的json文件地址");
	String fromAddress = credentials.getAddress();
	EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount(
			fromAddress, DefaultBlockParameterName.LATEST).sendAsync().get();
	BigInteger nonce = ethGetTransactionCount.getTransactionCount();
	
	Address address = new Address("交易到某个地址,可以理解为平台地址");
	Uint256 value = new Uint256(new BigInteger("交易数量,我用的代币是ZXC币,汇率是100000000"));
	List<Type> parametersList = new ArrayList<>();
	parametersList.add(address);
	parametersList.add(value);
	List<TypeReference<?>> outList = new ArrayList<>();
	Function function = new Function("transfer", parametersList, outList);
	String encodedFunction = FunctionEncoder.encode(function);
	System.out.println( DefaultGasProvider.GAS_PRICE);
	System.out.println(DefaultGasProvider.GAS_LIMIT);
	RawTransaction rawTransaction = RawTransaction.createTransaction(nonce,  (gasPrice,可以设置成默认)DefaultGasProvider.GAS_PRICE,
			new BigInteger([常玩代币的都知道,一般gasLimit都是60000]"60000"), "这里是代币的合约地址,不要弄错了", encodedFunction);
	byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
	String hexValue = Numeric.toHexString(signedMessage);
	EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get();
	//这里可以判断交易的Hash是否为空来判断交易是否成功,具体可以调试代码查看
	Object transactionHash = ethSendTransaction.getTransactionHash();
	System.out.println(transactionHash.toString());
}

其次,在使用过程中,遇到了一个大坑,当然这个坑是自己挖的。
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchFieldError: TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:982)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter 1. c a l l ( A b s t r a c t S h i r o F i l t e r . j a v a : 365 ) a t o r g . a p a c h e . s h i r o . s u b j e c t . s u p p o r t . S u b j e c t C a l l a b l e . d o C a l l ( S u b j e c t C a l l a b l e . j a v a : 90 ) a t o r g . a p a c h e . s h i r o . s u b j e c t . s u p p o r t . S u b j e c t C a l l a b l e . c a l l ( S u b j e c t C a l l a b l e . j a v a : 83 ) a t o r g . a p a c h e . s h i r o . s u b j e c t . s u p p o r t . D e l e g a t i n g S u b j e c t . e x e c u t e ( D e l e g a t i n g S u b j e c t . j a v a : 383 ) a t o r g . a p a c h e . s h i r o . w e b . s e r v l e t . A b s t r a c t S h i r o F i l t e r . d o F i l t e r I n t e r n a l ( A b s t r a c t S h i r o F i l t e r . j a v a : 362 ) a t o r g . a p a c h e . s h i r o . w e b . s e r v l e t . O n c e P e r R e q u e s t F i l t e r . d o F i l t e r ( O n c e P e r R e q u e s t F i l t e r . j a v a : 125 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 193 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 166 ) a t c o m . a l i b a b a . d r u i d . s u p p o r t . h t t p . W e b S t a t F i l t e r . d o F i l t e r ( W e b S t a t F i l t e r . j a v a : 123 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 193 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 166 ) a t o r g . s p r i n g f r a m e w o r k . w e b . f i l t e r . R e q u e s t C o n t e x t F i l t e r . d o F i l t e r I n t e r n a l ( R e q u e s t C o n t e x t F i l t e r . j a v a : 99 ) a t o r g . s p r i n g f r a m e w o r k . w e b . f i l t e r . O n c e P e r R e q u e s t F i l t e r . d o F i l t e r ( O n c e P e r R e q u e s t F i l t e r . j a v a : 107 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 193 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 166 ) a t o r g . s p r i n g f r a m e w o r k . w e b . f i l t e r . H t t p P u t F o r m C o n t e n t F i l t e r . d o F i l t e r I n t e r n a l ( H t t p P u t F o r m C o n t e n t F i l t e r . j a v a : 105 ) a t o r g . s p r i n g f r a m e w o r k . w e b . f i l t e r . O n c e P e r R e q u e s t F i l t e r . d o F i l t e r ( O n c e P e r R e q u e s t F i l t e r . j a v a : 107 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 193 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 166 ) a t o r g . s p r i n g f r a m e w o r k . w e b . f i l t e r . H i d d e n H t t p M e t h o d F i l t e r . d o F i l t e r I n t e r n a l ( H i d d e n H t t p M e t h o d F i l t e r . j a v a : 81 ) a t o r g . s p r i n g f r a m e w o r k . w e b . f i l t e r . O n c e P e r R e q u e s t F i l t e r . d o F i l t e r ( O n c e P e r R e q u e s t F i l t e r . j a v a : 107 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 193 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 166 ) a t o r g . s p r i n g f r a m e w o r k . w e b . f i l t e r . C h a r a c t e r E n c o d i n g F i l t e r . d o F i l t e r I n t e r n a l ( C h a r a c t e r E n c o d i n g F i l t e r . j a v a : 197 ) a t o r g . s p r i n g f r a m e w o r k . w e b . f i l t e r . O n c e P e r R e q u e s t F i l t e r . d o F i l t e r ( O n c e P e r R e q u e s t F i l t e r . j a v a : 107 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 193 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 166 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d W r a p p e r V a l v e . i n v o k e ( S t a n d a r d W r a p p e r V a l v e . j a v a : 198 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d C o n t e x t V a l v e . i n v o k e ( S t a n d a r d C o n t e x t V a l v e . j a v a : 96 ) a t o r g . a p a c h e . c a t a l i n a . a u t h e n t i c a t o r . A u t h e n t i c a t o r B a s e . i n v o k e ( A u t h e n t i c a t o r B a s e . j a v a : 478 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d H o s t V a l v e . i n v o k e ( S t a n d a r d H o s t V a l v e . j a v a : 140 ) a t o r g . a p a c h e . c a t a l i n a . v a l v e s . E r r o r R e p o r t V a l v e . i n v o k e ( E r r o r R e p o r t V a l v e . j a v a : 80 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d E n g i n e V a l v e . i n v o k e ( S t a n d a r d E n g i n e V a l v e . j a v a : 87 ) a t o r g . a p a c h e . c a t a l i n a . c o n n e c t o r . C o y o t e A d a p t e r . s e r v i c e ( C o y o t e A d a p t e r . j a v a : 342 ) a t o r g . a p a c h e . c o y o t e . h t t p 11. H t t p 11 P r o c e s s o r . s e r v i c e ( H t t p 11 P r o c e s s o r . j a v a : 799 ) a t o r g . a p a c h e . c o y o t e . A b s t r a c t P r o c e s s o r L i g h t . p r o c e s s ( A b s t r a c t P r o c e s s o r L i g h t . j a v a : 66 ) a t o r g . a p a c h e . c o y o t e . A b s t r a c t P r o t o c o l 1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol 1.call(AbstractShiroFilter.java:365)atorg.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)atorg.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)atorg.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)atorg.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)atorg.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)atcom.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)atorg.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)atorg.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)atorg.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)atorg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)atorg.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)atorg.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)atorg.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)atorg.apache.coyote.AbstractProtocolConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint S o c k e t P r o c e s s o r . d o R u n ( N i o E n d p o i n t . j a v a : 1455 ) a t o r g . a p a c h e . t o m c a t . u t i l . n e t . S o c k e t P r o c e s s o r B a s e . r u n ( S o c k e t P r o c e s s o r B a s e . j a v a : 49 ) a t j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r . r u n W o r k e r ( T h r e a d P o o l E x e c u t o r . j a v a : 1142 ) a t j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r SocketProcessor.doRun(NioEndpoint.java:1455) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor SocketProcessor.doRun(NioEndpoint.java:1455)atorg.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)atjava.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread W r a p p i n g R u n n a b l e . r u n ( T a s k T h r e a d . j a v a : 61 ) a t j a v a . l a n g . T h r e a d . r u n ( T h r e a d . j a v a : 745 ) C a u s e d b y : j a v a . l a n g . N o S u c h F i e l d E r r o r : T L S E C D H E E C D S A W I T H C H A C H A 2 0 P O L Y 130 5 S H A 256 a t o r g . w e b 3 j . p r o t o c o l . h t t p . H t t p S e r v i c e . &lt; c l i n i t &gt; ( H t t p S e r v i c e . j a v a : 37 ) a t c o m . b o o t d o . r i d e . s e r v i c e . i m p l . U s e r D r i v e r S e r v i c e I m p l . c h a n g e I n t o ( U s e r D r i v e r S e r v i c e I m p l . j a v a : 171 ) a t c o m . b o o t d o . r i d e . c o n t r o l l e r . U s e r D r i v e r C o n t r o l l e r . c h a n g e I n t o ( U s e r D r i v e r C o n t r o l l e r . j a v a : 143 ) a t c o m . b o o t d o . r i d e . c o n t r o l l e r . U s e r D r i v e r C o n t r o l l e r WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NoSuchFieldError: TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 at org.web3j.protocol.http.HttpService.&lt;clinit&gt;(HttpService.java:37) at com.bootdo.ride.service.impl.UserDriverServiceImpl.changeInto(UserDriverServiceImpl.java:171) at com.bootdo.ride.controller.UserDriverController.changeInto(UserDriverController.java:143) at com.bootdo.ride.controller.UserDriverController WrappingRunnable.run(TaskThread.java:61)atjava.lang.Thread.run(Thread.java:745)Causedby:java.lang.NoSuchFieldError:TLSECDHEECDSAWITHCHACHA20POLY1305SHA256atorg.web3j.protocol.http.HttpService.<clinit>(HttpService.java:37)atcom.bootdo.ride.service.impl.UserDriverServiceImpl.changeInto(UserDriverServiceImpl.java:171)atcom.bootdo.ride.controller.UserDriverController.changeInto(UserDriverController.java:143)atcom.bootdo.ride.controller.UserDriverController F a s t C l a s s B y S p r i n g C G L I B FastClassBySpringCGLIB FastClassBySpringCGLIB a 77 c 356 f . i n v o k e ( &lt; g e n e r a t e d &gt; ) a t o r g . s p r i n g f r a m e w o r k . c g l i b . p r o x y . M e t h o d P r o x y . i n v o k e ( M e t h o d P r o x y . j a v a : 204 ) a t o r g . s p r i n g f r a m e w o r k . a o p . f r a m e w o r k . C g l i b A o p P r o x y a77c356f.invoke(&lt;generated&gt;) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy a77c356f.invoke(<generated>)atorg.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)atorg.springframework.aop.framework.CglibAopProxyCglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
at com.bootdo.common.aspect.WebLogAspect.doAround(WebLogAspect.java:57)
at sun.reflect.GeneratedMethodAccessor132.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy D y n a m i c A d v i s e d I n t e r c e p t o r . i n t e r c e p t ( C g l i b A o p P r o x y . j a v a : 673 ) a t c o m . b o o t d o . r i d e . c o n t r o l l e r . U s e r D r i v e r C o n t r o l l e r DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) at com.bootdo.ride.controller.UserDriverController DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)atcom.bootdo.ride.controller.UserDriverController E n h a n c e r B y S p r i n g C G L I B EnhancerBySpringCGLIB EnhancerBySpringCGLIB$dafa0b7b.changeInto()
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.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
… 60 common frames omitted

后来查询资料发现,引入web3j的时候,会依赖引用okhttp这个jar。项目本身的pom中使用了七牛云,也引入了这个jar。导致jar的重复调用。

  • 1
    点赞
  • 2
    评论
  • 1
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

p_981215

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值