@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