【问题标题】:Consider defining a bean of type 'net.corda.core.messaging.CordaRPCOps' in your configuration考虑在你的配置中定义一个“net.corda.core.messaging.CordaRPCOps”类型的bean
【发布时间】:2018-12-21 18:31:03
【问题描述】:

无法在我的 CustomController 中使用 CordaRPCOps 实现方法,

@RequestMapping(value="/peers", produces = MediaType.APPLICATION_JSON)
    public Map<String, List<String>> peers() throws Exception
    {

        CordaRPCOps proxy=rpc.getParameterValue("proxy");

        Party myIdentity= proxy.nodeInfo().getLegalIdentities().get(0);

        return ImmutableMap.of("peers", rpcOpsImpl.networkMapSnapshot()
                .stream()
                .filter(nodeInfo -> nodeInfo.getLegalIdentities().get(0) != myIdentity)
                .map(it -> it.getLegalIdentities().get(0).getName().getOrganisation())
                .collect(toList()));
        }

在构建 runPartyAServer 时出错,

APPLICATION FAILED TO START

Description:

Field services in net.corda.server.controllers.CustomController required a bean of type 'net.corda.core.messaging.CordaRPCOps' that could not be found.


Action:

Consider defining a bean of type 'net.corda.core.messaging.CordaRPCOps' in your configuration.

【问题讨论】:

  • 你能得到代码来显示rpc变量在哪里被实例化吗?
  • @Controller public class CustomController { private NodeRPCConnection rpc;私有 CordaRPCOps rpcOpsImpl; } 从 NodeRPCConnection 获取代理值,使用 CordaRPCOps proxy=rpc.getParameterValue("proxy");
  • 谁能帮我解决这个异常

标签: spring webserver corda


【解决方案1】:

正如错误消息所说,您必须定义一个 CordaRPCConnection/CordaRPCOps 类型的 bean。

类似于:

@Bean
private fun connect(): CordaRPCConnection {
    val hostAndPort = NetworkHostAndPort(configuration.host, configuration.port)
    val client = CordaRPCClient(hostAndPort)
    val connection = client.start(configuration.user, configuration.password)
    return connection;
}

默认情况下,我们不提供任何 DI 容器集成。

【讨论】:

  • 我的问题不在于 rpc 变量,我在使用 CordaRPCops 方法时无法使用 rpcOps 变量,这是我的变量减速私有 CordaRPCOps rpcOps;在我的自定义控制器中,出现错误,net.corda.server.controllers.CustomController 中的字段服务需要一个无法找到的“net.corda.core.messaging.CordaRPCOps”类型的 bean。
  • 我已经导入了需要的一个,import net.corda.core.messaging.CordaRPCOps;
  • 您能否为您的代码块使用正确的格式。不可能看到发生了什么。你错过了重点。 Spring 告诉你没有定义 Bean。请参阅上文以了解如何添加新 bean。
猜你喜欢
  • 2018-06-22
  • 1970-01-01
  • 2020-08-01
  • 2019-02-14
  • 2019-05-10
  • 2019-09-04
  • 2020-05-23
  • 2019-02-05
  • 1970-01-01
相关资源
最近更新 更多