You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quarkus中Kotlin与Java互操作问题:CDI及EventBus异常排查

Quarkus Java应用引入Kotlin类的CDI与EventBus问题

案例1 - EventBus事件未触发问题

Kotlin事件消费类代码:

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

Java端点调用代码:

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

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

问题:调用eventBus.send发送事件后,Kotlin类中的greeting方法从未被触发,但使用Java类标注@ConsumeEvent("KotlinTest")时可正常接收事件。

案例2 - CDI注入失败问题

Kotlin服务类代码:

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

Java端点注入代码:

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

  @Inject
  GreetingService greetingService;
}

编译报错信息:

error: cannot find symbol GreetingService greetingService;

补充说明:已知CDI可使用@field:Default注解,但该注解仅适用于Kotlin代码;尝试构造注入也遇到相同错误,代码如下:

@POST
@Path("/execute")
@Inject
public Response execute(GreetingService greetingService, String input) {
}

内容的提问来源于stack exchange,提问作者Charlie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 18:16:04