我有一个 Quarkus 反应式应用程序,我在其中使用自定义 Jackson 解串器。在这个反序列化器中,我必须调用一个数据库。
public class MyTypeDeserializer extends StdDeserializer<MyType> {
public MyTypeDeserializer() {
this(null);
}
public MyTypeDeserializer(Class<?> vc) {
super(vc);
}
@Override
public MyType deserialize(
JsonParser jsonparser, DeserializationContext context)
throws IOException {
// Lookup the instantiated db service which has been added to jackson on application startup
MyTypeService service = (MyTypeService) context
.findInjectableValue("myTypeServiceBean", null, null);
// Get the info from json
String info = jsonparser.getText();
// Find myType instance in database
return service.find("info = :info", Parameters.with("info", info)).await().indefinitely();
}
运行此代码会导致:
java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-5
我了解此错误告诉我调用线程因await().indefinitely()调用而被阻塞。但是我找不到从数据库中检索实例的另一种方法。我必须等到从数据库中加载数据。如何做到这一点?