【问题标题】:no suitable method found for configured finagle in Java code在 Java 代码中没有为配置的 finagle 找到合适的方法
【发布时间】:2018-10-29 20:57:17
【问题描述】:

我有一个 Java 多语言应用程序,它主要包含 Java 代码,也使用少量 Scala 库。

下面的 Scala 代码编译得很好。

import com.twitter.finagle.Http.Client
import com.twitter.finagle.Http
import com.twitter.finagle.param.Logger

object Main extends App {

  private val loggerFinagle = java.util.logging.Logger.getLogger("FinagleLogger")

  val client: Client = Http.client
    .configured(Logger(loggerFinagle))
}

我在java中写了和下面一样的代码

import com.twitter.finagle.Http;
import com.twitter.finagle.param.Logger;

public class JavaMain {
    public static void main(String[] args) {

        java.util.logging.Logger loggerFinagle = java.util.logging.Logger.getLogger("FinagleLogger");

        Http.client()
               .configured(new Logger(loggerFinagle));
    }
}

当我编译代码时出现以下错误 -

[info] Compiling 1 Scala source and 1 Java source to /Users/rajkumar.natarajan/Documents/Coding/finagle-errors/target/scala-2.12/classes ...
[error] /Users/rajkumar.natarajan/Documents/Coding/finagle-errors/src/main/java/JavaMain.java:10:1: no suitable method found for configured(com.twitter.finagle.param.Logger)
[error]     method com.twitter.finagle.Stack.Parameterized.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (actual and formal argument lists differ in length))
[error]     method com.twitter.finagle.Stack.Parameterized.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error]     method com.twitter.finagle.client.StackClient.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (actual and formal argument lists differ in length))
[error]     method com.twitter.finagle.client.StackClient.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error]     method com.twitter.finagle.client.EndpointerStackClient.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (actual and formal argument lists differ in length))
[error]     method com.twitter.finagle.client.EndpointerStackClient.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error]     method com.twitter.finagle.Http.Client.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error] Http.client()
[error]                .configured

看起来我必须通过元组,但我不知道如何。

github中的项目是here

下面是我的项目的依赖细节-

Scala 版本 - 2.12.6

Java 版本 - 1.8.0_151

finagle 版本 - 7.1.0

【问题讨论】:

    标签: scala finagle twitter-finagle


    【解决方案1】:

    According to the docs,您需要在参数上调用mk() 方法,因此类似以下的内容应该创建正确的元组:

        Http.client()
               .configured(new Logger(loggerFinagle).mk());
    

    【讨论】:

      猜你喜欢
      • 2019-04-30
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      • 2014-08-27
      • 2021-06-19
      相关资源
      最近更新 更多