首页 > 解决方案 > Corda Accounts 使用 java 创建帐户时由于依赖项错误而失败

问题描述

We are trying to create accounts using java and to create accounts we need to use the "accountservice" library (com.r3.corda.lib.accounts.workflows.accountService => kotlin) but in java we are not able to get it in a same way (com.r3.corda.lib.accounts.workflows.services.AccountService => java).So What we have did is we have imported the above library in java code and tried to inject using autowired annotation but it is giving below error as:Compiling with JDK Java compiler API. /home/lti-blockchain/Desktop/teju/corda_practice/corda_accounts/Corda-accounts/workflows/src/main/java/com/lti/blockchain/corda/flows/CreateAccountFlow.java:7: error: package org.springframework.beans.factory.annotation does not exist import org.springframework.beans.factory.annotation.Autowired; ^ /home/lti-blockchain/Desktop/teju/corda_practice/corda_accounts/Corda-accounts/workflows/src/main/java/com/lti/blockchain/corda/flows/CreateAccountFlow.java:23: error: cannot find symbol @Autowired ^ symbol: class Autowired location: class CreateAccountFlow Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 2 errors :workflows:compileJava (Thread[Task worker for ':' Thread 3,5,main]) completed. Took 0.196 secs.FAILURE: Build failed with an exception.* What went wrong: Execution failed for task ':workflows:compileJava'.

编译失败;有关详细信息,请参阅编译器错误输出。

标签: javaspringgradlecorda

解决方案


  1. 您的问题格式错误,很难阅读;请下次使用降价样式(特别是围绕代码块的 3 个反引号:https ://www.markdownguide.org/extended-syntax/#fenced-code-blocks )。
  2. AccountService是一个接口而不是一个类,所以你不能使用它;你需要使用它的实现类KeyManagementBackedAccountService
  3. 要获得服务,请在您的流程中使用它:
getServiceHub().cordaService(KeyManagementBackedAccountService.class);
  1. 您不需要该服务来创建帐户,该服务只是一个使事情变得更容易的实用程序。如果你打开它,你会看到它调用了你可以自己使用的流:
// As you can see, this service method calls "CreateAccount()" flow.
@Suspendable
override fun createAccount(name: String): CordaFuture<StateAndRef<AccountInfo>> {
    return flowAwareStartFlow(CreateAccount(name))
}
// So inside your flow you can do this instead of calling the service method:
subFlow(new CreateAccount("some username"));

推荐阅读