Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用比特币支付的Spring网页_Java_Spring_Spring Mvc_Bitcoinj - Fatal编程技术网

Java 使用比特币支付的Spring网页

Java 使用比特币支付的Spring网页,java,spring,spring-mvc,bitcoinj,Java,Spring,Spring Mvc,Bitcoinj,我正在尝试编写一个简单的程序,它将成为比特币支付的web客户端。我使用bitcoinj作为库;但是会有错误 2017-04-12 15:07:35.099 ERROR 14507 --- [inj user thread] org.bitcoinj.core.Context : Performing thread fixup: you are accessing bitcoinj via a thread that has not had any context

我正在尝试编写一个简单的程序,它将成为比特币支付的web客户端。我使用bitcoinj作为库;但是会有错误

2017-04-12 15:07:35.099 ERROR 14507 --- [inj user thread] 
org.bitcoinj.core.Context                : Performing thread fixup: 
you are accessing bitcoinj via a thread that has not had any context 
set on it.
2017-04-12 15:07:35.099 ERROR 14507 --- [inj user thread]     
org.bitcoinj.core.Context                : This error has been 
corrected for, but doing this makes your app less robust.
2017-04-12 15:07:35.099 ERROR 14507 --- [inj user thread] 
org.bitcoinj.core.Context                : You should use 
Context.propagate() or a ContextPropagatingThreadFactory.
2017-04-12 15:07:35.099 ERROR 14507 --- [inj user thread] 
org.bitcoinj.core.Context                : Please refer to the user 
guide for more information about this.
2017-04-12 15:07:35.099 ERROR 14507 --- [inj user thread] 
org.bitcoinj.core.Context                : Thread name is bitcoinj 
user thread.
我只是想知道如何在Spring框架上实现我的网页上的比特币支付

@组成部分 公共类比特币服务{

private final NetworkParameters params;
private final WalletAppKit kit;

@PreDestroy
private void close(){
    System.out.println("shutting down again");
    kit.stopAsync();
    kit.awaitTerminated();
}

public BitcoinjService() {
    params = TestNet3Params.get();
    kit = new WalletAppKit(params, new File("."), "walletappkit-example");
    kit.startAsync();
    kit.awaitRunning();

    kit.wallet().addCoinsReceivedEventListener((wallet, tx, prevBalance, newBalance) -> {
        System.out.println("-----> coins resceived: " + tx.getHashAsString());
        System.out.println("received: " + tx.getValue(wallet));
    });

    kit.wallet().addCoinsSentEventListener((wallet, tx, prevBalance, newBalance) -> System.out.println("coins sent"));

    kit.wallet().addKeyChainEventListener(keys -> System.out.println("new key added"));

    kit.wallet().addScriptsChangeEventListener((wallet, scripts, isAddingScripts) -> System.out.println("new script added"));

    kit.wallet().addTransactionConfidenceEventListener((wallet, tx) -> {
        System.out.println("-----> confidence changed: " + tx.getHashAsString());
        TransactionConfidence confidence = tx.getConfidence();
        System.out.println("new block depth: " + confidence.getDepthInBlocks());
    });

    // Ready to run. The kit syncs the blockchain and our wallet event listener gets notified when something happens.
    // To test everything we create and print a fresh receiving address. Send some coins to that address and see if everything works.
    System.out.println("send money to: " + kit.wallet().freshReceiveAddress().toString());

}


public String  getFreshReciveAddress() {
    Context.propagate(new Context(params));
    return kit.wallet().currentReceiveAddress().toString();
}

public String getBalance(){
    Context.propagate(new Context(params));
    return kit.wallet().getBalance().toFriendlyString();
}

public void sendTo(String address) {
    Context.propagate(new Context(params));
    // Get the address 1RbxbA1yP2Lebauuef3cBiBho853f7jxs in object form.
    Address targetAddress = Address.fromBase58(params, address);
    // Do the send of 1 BTC in the background. This could throw InsufficientMoneyException.
    Wallet.SendResult result = null;
    try {
        result = kit.wallet().sendCoins(kit.peerGroup(), targetAddress, Coin.parseCoin(kit.wallet().getBalance().toPlainString()).minus(Coin.parseCoin("0.0005")));//TODO: calulating fee
        kit.wallet().saveToFile(new File("TestFile"));
        result.broadcastComplete.get();
    } catch (InsufficientMoneyException | IOException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }

}

错误消息告诉您应该使用Context.propagate()或contextpropagationthreadfactory。[…]请参阅《用户指南》了解更多信息。-您是否已经阅读了该指南?如您所见“Context.propagate(新上下文(参数));”我尝试将其添加到每个方法中。