在 Java 代码中找不到适合配置的 finagle 的方法

no suitable method found for configured finagle in Java code

我有 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

According to the docs,你需要在参数上调用 mk() 方法,所以像下面这样的东西应该创建正确的元组:

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