Quarkus Kotlin/Java 互操作性如何工作?

问题描述 投票:0回答:1

我有一个常规的 Quarkus Java 应用程序,我想通过 CDI 引入一些 Kotlin 类以及事件总线,但以下内容并不像我想象的那样工作。

案例 #1 - 事件总线

Kotlin 类

@ApplicationScoped
class GreetingServiceBus {
    @ConsumeEvent("KotlinTest")
    fun greeting(name: String) {
        System.out.println("hello $name");
    }
}

我像这样从 Resteasy 类中调用它,但永远不会调用问候语(这对于带有 @ConsumeEvent("KotlinTest") 的 Java 类来说效果很好

@Path("/api")
public class ApiExecute {
  @Inject
  EventBus eventBus;

  @POST
  @Path("/execute")
  public Response execute() {
    eventBus.send("KotlinTest", "Hello");

案例#2 - CDI

Kotlin 类

@ApplicationScoped
class GreetingService {
    fun greeting(name: String): String {
        return "hello $name"
    }
}

Resteasy 端点

@Path("/api")
public class ApiExecute {

  @Inject
  GreetingService greetingService;

错误

错误:找不到符号 GreetingServicegreetingService;

我看到一些关于将其与 CDI“@field: Default”一起使用的信息,但我相信这仅在 Kotlin 中可用,而不是在 Java 中可用?

也尝试过构造函数注入,但同样的问题

  @POST
  @Path("/execute")
  @Inject
  public Response execute(GreetingService greetingService, String input) {
kotlin interop quarkus
1个回答
0
投票

构造函数和字段注入都应该可以在 Kotlin 中正常工作。

看看我们的集成测试以了解各种用法

© www.soinside.com 2019 - 2024. All rights reserved.