java发布合约_java 调用 ethereum 的智能合约

@ajian1984 我是用的web3j这个工具与ethereum进行通讯,因为我的项目是一个B/S架构的,用的java spring boot你架构,我在项目里创建了与ethereum接口类:

package com.example.mortgage.ethereum;

import org.web3j.protocol.Web3j;

import org.web3j.protocol.http.HttpService;

public class Web3JClient {

private static String URL = "http://10.10.10.4:61911/";

public Web3JClient(){}

public volatile static Web3j web3j;

public static Web3j getClient(){

if(web3j==null){

synchronized (Web3JClient.class){

if(web3j==null){

web3j = Web3j.build(new HttpService(URL));

}

}

}

return web3j;

}

}

然后在我的控制器里调用:

public class PlatformController {

@Autowired

PlatformService platformService;

@RequestMapping("/index")

public String index(Model model){

try{

Web3j web3j;

Web3JClient web3jClient=new Web3JClient();

web3j=Web3JClient.getClient();

}catch (Exception e) {

e.printStackTrace();

}

return "index";

}

}

在Web3j.build(new HttpService(URL))这里出错,我这个端口我用telnet 测试,是没问题的,以下是出错信息:

2018-05-10 12:34:48.768 ERROR 9988 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: rx/schedulers/Schedulers] with root cause

java.lang.ClassNotFoundException: rx.schedulers.Schedulers

at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_161]

at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_161]

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_161]

at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_161]

at org.web3j.protocol.rx.JsonRpc2_0Rx.(JsonRpc2_0Rx.java:39) ~[core-2.2.1.jar:na]

at org.web3j.protocol.core.JsonRpc2_0Web3j.(JsonRpc2_0Web3j.java:90) ~[core-2.2.1.jar:na]

at org.web3j.protocol.core.JsonRpc2_0Web3j.(JsonRpc2_0Web3j.java:83) ~[core-2.2.1.jar:na]

at org.web3j.protocol.Web3j.build(Web3j.java:14) ~[core-2.2.1.jar:na]

at com.example.mortgage.ethereum.Web3JClient.getClient(Web3JClient.java:17) ~[classes/:na]

at com.example.mortgage.controller.PlatformController.index(PlatformController.java:50) ~[classes/:na]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]

at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]

at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]

at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) ~[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) ~[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]

at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值