当前位置: 首页 > 知识库问答 >
问题:

在尝试将Hyperledger fabric SDK与Spring Boot集成时,出现以下错误

欧阳杰
2023-03-14

我正在尝试将Hyperledger fabric SDK集成到Spring Boot中,当我运行应用程序时,我遇到以下错误,

java.lang.UnsupportedOperationException: null
    at javax.json.spi.JsonProvider.createObjectBuilder(JsonProvider.java:281) ~[javax.json-1.1.4.jar:1.1.4]
    at javax.json.Json.createObjectBuilder(Json.java:327) ~[javax.json-1.1.4.jar:1.1.4]
    at org.hyperledger.fabric.sdk.NetworkConfig.fromYamlStream(NetworkConfig.java:342) ~[fabric-sdk-java-1.4.8.jar:na]
    at org.hyperledger.fabric.gateway.impl.GatewayImpl$Builder.networkConfig(GatewayImpl.java:99) ~[fabric-gateway-java-1.4.3.jar:na]
    at org.hyperledger.fabric.gateway.impl.GatewayImpl$Builder.networkConfig(GatewayImpl.java:88) ~[fabric-gateway-java-1.4.3.jar:na]
    at org.hyperledger.fabric.gateway.impl.GatewayImpl$Builder.networkConfig(GatewayImpl.java:69) ~[fabric-gateway-java-1.4.3.jar:na]
    at com.person.fabricclient.controllers.PersonController.getPerson(PersonController.java:69) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_242]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_242]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_242]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_242]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]

下面是rest控制器代码,

   @RequestMapping(value = "/hello/createperson",method = RequestMethod.GET)
    public String getPerson() throws IOException {
        Gateway.Builder builder = Gateway.createBuilder();

        try {
            // A wallet stores a collection of identities
            Path walletPath = Paths.get("/home/Fabric-samples_1.4/fabric-samples/commercial-paper/organization/magnetocorp/identity/user/isabella/wallet");
            Wallet wallet = Wallet.createFileSystemWallet(walletPath);

            String userName = "User1@org1.example.com";

            Path connectionProfile = Paths.get("/home/Fabric-samples_1.4/fabric-samples/commercial-paper/organization/magnetocorp/gateway/networkConnection.yaml");

            // Set connection options on the gateway builder
            builder.identity(wallet, userName).networkConfig(connectionProfile).discovery(false);

            // Connect to gateway using application specified parameters
            try(Gateway gateway = builder.connect()) {

                // Access PaperNet network
                System.out.println("Use network channel: mychannel.");
                Network network = gateway.getNetwork("mychannel");

                // Get addressability to commercial paper contract
                System.out.println("Use org.papernet.commercialpaper smart contract.");
                Contract contract = network.getContract("person", "org.go.smartcontract");

                // Issue commercial paper
                System.out.println("Submit commercial paper issue transaction.");
                byte[] response = contract.submitTransaction("createCar", "go", "Hello", "2020-05-31");

                // Process response
                System.out.println("Process issue transaction response.");
//                CommercialPaper paper = CommercialPaper.deserialize(response);
//                System.out.println(paper);
            } catch (TimeoutException e) {
                e.printStackTrace();
            } catch (ContractException e) {
                e.printStackTrace();
            }
        } catch (InterruptedException | IOException e) {
            e.printStackTrace();
            System.exit(-1);
        }
        return "created";
    }

当我尝试调试时,这个问题发生在下面的类中,当我在Spring Boot下运行时,服务加载器返回一个对象,但是当我在没有Spring Boot的情况下尝试时,服务加载器不返回任何对象,并且执行这一行

Class<?> clazz = Class.forName("org.glassfish.json.JsonProviderImpl");

在接下来的课上。

    //
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package javax.json.spi;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonBuilderFactory;
import javax.json.JsonException;
import javax.json.JsonMergePatch;
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonPatch;
import javax.json.JsonPatchBuilder;
import javax.json.JsonPointer;
import javax.json.JsonReader;
import javax.json.JsonReaderFactory;
import javax.json.JsonString;
import javax.json.JsonStructure;
import javax.json.JsonValue;
import javax.json.JsonWriter;
import javax.json.JsonWriterFactory;
import javax.json.stream.JsonGenerator;
import javax.json.stream.JsonGeneratorFactory;
import javax.json.stream.JsonParser;
import javax.json.stream.JsonParserFactory;

public abstract class JsonProvider {
    private static final String DEFAULT_PROVIDER = "org.glassfish.json.JsonProviderImpl";

    protected JsonProvider() {
    }

    public static JsonProvider provider() {
        ServiceLoader<JsonProvider> loader = ServiceLoader.load(JsonProvider.class);
        Iterator<JsonProvider> it = loader.iterator();
        if (it.hasNext()) {
            return (JsonProvider)it.next();
        } else {
            try {
                Class<?> clazz = Class.forName("org.glassfish.json.JsonProviderImpl");
                return (JsonProvider)clazz.newInstance();
            } catch (ClassNotFoundException var3) {
                throw new JsonException("Provider org.glassfish.json.JsonProviderImpl not found", var3);
            } catch (Exception var4) {
                throw new JsonException("Provider org.glassfish.json.JsonProviderImpl could not be instantiated: " + var4, var4);
            }
        }
    }

    public abstract JsonParser createParser(Reader var1);

    public abstract JsonParser createParser(InputStream var1);

    public abstract JsonParserFactory createParserFactory(Map<String, ?> var1);

    public abstract JsonGenerator createGenerator(Writer var1);

    public abstract JsonGenerator createGenerator(OutputStream var1);

    public abstract JsonGeneratorFactory createGeneratorFactory(Map<String, ?> var1);

    public abstract JsonReader createReader(Reader var1);

    public abstract JsonReader createReader(InputStream var1);

    public abstract JsonWriter createWriter(Writer var1);

    public abstract JsonWriter createWriter(OutputStream var1);

    public abstract JsonWriterFactory createWriterFactory(Map<String, ?> var1);

    public abstract JsonReaderFactory createReaderFactory(Map<String, ?> var1);

    public abstract JsonObjectBuilder createObjectBuilder();

    public JsonObjectBuilder createObjectBuilder(JsonObject object) {
        throw new UnsupportedOperationException();
    }

    public JsonObjectBuilder createObjectBuilder(Map<String, Object> map) {
        throw new UnsupportedOperationException();
    }

    public abstract JsonArrayBuilder createArrayBuilder();

    public JsonArrayBuilder createArrayBuilder(JsonArray array) {
        throw new UnsupportedOperationException();
    }

    public JsonPointer createPointer(String jsonPointer) {
        throw new UnsupportedOperationException();
    }

    public JsonPatchBuilder createPatchBuilder() {
        throw new UnsupportedOperationException();
    }

    public JsonPatchBuilder createPatchBuilder(JsonArray array) {
        throw new UnsupportedOperationException();
    }

    public JsonPatch createPatch(JsonArray array) {
        throw new UnsupportedOperationException();
    }

    public JsonPatch createDiff(JsonStructure source, JsonStructure target) {
        throw new UnsupportedOperationException();
    }

    public JsonMergePatch createMergePatch(JsonValue patch) {
        throw new UnsupportedOperationException();
    }

    public JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) {
        throw new UnsupportedOperationException();
    }

    public JsonArrayBuilder createArrayBuilder(Collection<?> collection) {
        throw new UnsupportedOperationException();
    }

    public abstract JsonBuilderFactory createBuilderFactory(Map<String, ?> var1);

    public JsonString createValue(String value) {
        throw new UnsupportedOperationException();
    }

    public JsonNumber createValue(int value) {
        throw new UnsupportedOperationException();
    }

    public JsonNumber createValue(long value) {
        throw new UnsupportedOperationException();
    }

    public JsonNumber createValue(double value) {
        throw new UnsupportedOperationException();
    }

    public JsonNumber createValue(BigDecimal value) {
        throw new UnsupportedOperationException();
    }

    public JsonNumber createValue(BigInteger value) {
        throw new UnsupportedOperationException();
    }
}

共有1个答案

裴金鑫
2023-03-14

问题在于服务加载器,我不得不提到它应该在meta_inf/services/中加载的适当类,文件应该包含应该加载的类。

 类似资料:
  • 基本上我是按照这个指示做的:http://thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/ 但结果是: 尚未找到任何服务器 请求方法:获取请求URL:http://52.25.226.143/admin/ Django版本:1.5.11异常类型:ServerSelectionTimeoutError异常

  • 我试图在Windows7上使用Tomcat7添加ApacheSolr4.6。 另外,我将solr,solrj和log4j添加到tomcat lib文件夹中。我复制了solr web porlet到增殖和尝试启动服务器,但我得到异常。 谁能告诉我这个错误是怎么回事吗。

  • 我试图将Bean验证api-javax.Validation和hibernate-validator与Spring MVC应用程序集成在一起。我可以看出,当REST控制器方法不使用BindingResult参数时,服务器会正常启动并工作。但是当我在函数签名中使用BindingResult arg时,我会看到如下运行时错误 代码: .....}

  • 错误代码1064,SQL状态42000:您的SQL语法中有一个错误;请查看与您的MySQL server版本相对应的手册,以便在第2行“Begin INSERT INTO(,,)值”附近使用正确的语法

  • 尝试在IntelliJ中构建我的第一个helloWorld程序时遇到以下同步错误。 我第一次在运行Windows 10的计算机上安装了IntelliJ。

  • 我正在尝试运行以下Sqoop命令: 然而,我得到了这个错误: 17/02/04 00:04:53 警告安全。用户组信息: 特权行动例外作为:avinash (身份验证:简单) 原因:java.io.文件不发现异常: 文件不存在: hdfs://localhost:9000/home/avinash/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/lib/slf4j-api-