java - 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'.
编译失败;有关详细信息,请参阅编译器错误输出。
解决方案
- 您的问题格式错误,很难阅读;请下次使用降价样式(特别是围绕代码块的 3 个反引号:https ://www.markdownguide.org/extended-syntax/#fenced-code-blocks )。
AccountService
是一个接口而不是一个类,所以你不能使用它;你需要使用它的实现类KeyManagementBackedAccountService
。- 要获得服务,请在您的流程中使用它:
getServiceHub().cordaService(KeyManagementBackedAccountService.class);
- 您不需要该服务来创建帐户,该服务只是一个使事情变得更容易的实用程序。如果你打开它,你会看到它调用了你可以自己使用的流:
// 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"));
推荐阅读
- google-cloud-functions - google 函数:从函数访问 google 存储桶
- android - Android 9.0 中的 PhoneStateListener onCallStateChanged 方法参数“传入号码”为空?
- reactjs - 在 Axios 中的 GET 方法 URL 搜索参数中发送嵌套对象
- grpc - 请求 tf 服务服务器时出现 Connect Failed 错误,在 windows 中一切正常
- java - 来自 Linux 服务器本身的 JVisualVM 结果
- javascript - 将上下文传递给 Sinon 存根的假函数
- javascript - 在 Alexa Skill 中使用 YouTube 音频链接
- node.js - 带有 Node.JS 和 Express 和 .ejs 的 SPA
- python - 如何解决 pycharm 中的“从 bitly_api 导入连接、BitlyError、错误”?
- java - 使用 kerberos 访问 hive jdbc 和 spark-hive