当前位置: 首页 > 知识库问答 >
问题:

Quakus MongoDB在本地构建中更改流NullPointerExctive

相洛华
2023-03-14

我正在构建一个Quarkus应用程序,它使用mongoDB更改流功能与反应客户端。

如果我从Intellij本地启动应用程序,一切正常,但当我构建本机应用程序并在docker映像中运行时,我收到了这个错误

2021-05-24 14:32:51,983 INFO [org.mon.dri.connection] (main) Opened connection [connectionId{localValue:13, serverValue:220678}] to cluster0-shard-00-02.plt2x.mongodb.net:27017
2021-05-24 14:32:52,146 INFO [org.mon.dri.connection] (main) Closed connection [connectionId{localValue:13, serverValue:220678}] to cluster0-shard-00-02.plt2x.mongodb.net:27017 because the pool has been closed.
2021-05-24 14:32:52,197 ERROR [io.qua.run.Application] (main) Failed to start application (with profile prod): java.lang.NullPointerException
at com.mongodb.client.model.changestream.ChangeStreamDocumentCodec.<init>(ChangeStreamDocumentCodec.java:45)
at com.mongodb.client.model.changestream.ChangeStreamDocument.createCodec(ChangeStreamDocument.java:296)
at com.mongodb.reactivestreams.client.internal.ChangeStreamPublisherImpl.<init>(ChangeStreamPublisherImpl.java:65)
at com.mongodb.reactivestreams.client.internal.MongoCollectionImpl.watch(MongoCollectionImpl.java:277)
at io.quarkus.mongodb.impl.ReactiveMongoCollectionImpl.watch(ReactiveMongoCollectionImpl.java:360)
at com.eventmanager.event.EventService.initOrderStream(EventService.java:89)
at com.eventmanager.event.EventService.init(EventService.java:46)
at com.eventmanager.event.EventService_Bean.create(EventService_Bean.zig:376)
at com.eventmanager.event.EventService_Bean.create(EventService_Bean.zig:392)
at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
at io.quarkus.arc.impl.AbstractSharedContext.access$000(AbstractSharedContext.java:14)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:17)
at com.eventmanager.event.EventService_ClientProxy.arc$delegate(EventService_ClientProxy.zig:67)
at com.eventmanager.event.EventService_ClientProxy.arc_contextualInstance(EventService_ClientProxy.zig:82)
at com.eventmanager.event.EventService_Observer_Synthetic_d70cd75bf32ab6598217b9a64a8473d65e248c05.notify(EventService_Observer_Synthetic_d70cd75bf32ab6598217b9a64a8473d65e248c05.zig:94)
at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:283)
at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:268)
at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:70)
at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:128)
at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:97)
at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy_0(LifecycleEventsBuildStep$startupEvent1144526294.zig:87)
at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(LifecycleEventsBuildStep$startupEvent1144526294.zig:40)
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:609)
at io.quarkus.runtime.Application.start(Application.java:90)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:100)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)

我使用这个命令来构建本机应用程序,因为我需要在windows上本地构建它,并在heroku上delpoy它:

mvn package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-native-image:21.0.0-java11

这是我初始化变更流并启动集合监视的类和方法

@Inject
ReactiveMongoClient mongoClient;

private void initOrderStream() {
    ReactiveMongoDatabase database = mongoClient.getDatabase("database");
    ReactiveMongoCollection<Order> dataCollection = database.getCollection("order", Order.class);
    ChangeStreamOptions options = new ChangeStreamOptions().fullDocument(FullDocument.UPDATE_LOOKUP);


    List<Bson> pipeline = Collections.singletonList(
            Aggregates.match(
                    Filters.and(
                            Filters.eq("operationType", "update"),
                            Filters.eq("updateDescription.updatedFields.orderStatus", "PENDING")
                    )
            )
    );

    Multi<ChangeStreamDocument<Order>> publisher = dataCollection.watch(pipeline, Order.class, options);
    publisher.subscribe().with(eventListener.getOrderListener());
}

这就是听众方法

public Consumer<ChangeStreamDocument<Order>> getOrderListener() {
    return message -> {
        Order order = message.getFullDocument();
        saveEvent(order);
    };
}

我不理解这个错误,查看mongo客户机库的源代码,其中有nullpointer异常,我发现错误在构造函数中

ChangeStreamDocumentCodec(final Class<TResult> fullDocumentClass, final CodecRegistry codecRegistry) {

    ClassModelBuilder<ChangeStreamDocument> classModelBuilder = ClassModel.builder(ChangeStreamDocument.class);
    ((PropertyModelBuilder<TResult>) classModelBuilder.getProperty("fullDocument")).codec(codecRegistry.get(fullDocumentClass));
    ((PropertyModelBuilder<OperationType>) classModelBuilder.getProperty("operationType")).codec(OPERATION_TYPE_CODEC);
    ClassModel<ChangeStreamDocument> changeStreamDocumentClassModel = classModelBuilder.build();

    PojoCodecProvider provider = PojoCodecProvider.builder()
            .register(MongoNamespace.class)
            .register(UpdateDescription.class)
            .register(TruncatedArray.class)
            .register(changeStreamDocumentClassModel)
            .build();

    CodecRegistry registry = fromRegistries(fromProviders(provider, new BsonValueCodecProvider()), codecRegistry);
    this.codec = (Codec<ChangeStreamDocument<TResult>>) (Codec<? extends ChangeStreamDocument>) registry.get(ChangeStreamDocument.class);
}

空指针所在的行是:

((PropertyModelBuilder<TResult>) classModelBuilder.getProperty("fullDocument")).codec(codecRegistry.get(fullDocumentClass));

因此,我试图删除fullDocument选项,但错误依然存在。

知道只有当我在docker中运行应用程序时才会导致这个错误吗?谢谢

共有1个答案

宰父保臣
2023-03-14

这在这里刚刚修复,将在1.13.52.0.0中提供。Alpha4

 类似资料:
  • 我试图为android构建一个React原生应用程序,但在我的企业中,外部存储库被阻止(不允许外部网络)。 因此,我们使用内部maven存储库来获取工件。但是我在构建react本机应用程序时遇到了一些问题,因为具有节点模块依赖性的项目需要构建引用存储库的本机android代码(我不想手动重写node_modules/react*/android/build.gradle)。 但是当我启动gradl

  • 我想试着测试一些javascript时区的东西,我需要把我的浏览器放到一个不同的时区,我在英国,所以它被设置为GMT,在冬天刚好和UTC一样,所以不可能计算出差异是否已经被考虑在内。 例如,我想把我的PC放入EST中,但我在Chrome选项中找不到任何东西,我尝试在Win10选项中更改我的时区,但浏览器忽略了它。重启Chrome没有任何帮助,即使我的PC确定它在EST并且我的Windows工具栏中

  • 问题内容: 我在想类似的东西: 哪种Java JSON库最适合这种流畅的构建? 更新 :我包GSON,并得到几乎理想的结果...... 问题答案: 我正在使用org.json库,发现它很好并且很友好。 例: 输出:

  • null 有人知道我如何解决我的问题吗?或者能给我一些有用的信息吗?

  • 如您所见,其中没有。那么,当我的电脑上安装了27个版本时,为什么我的android工作室会寻找这个特定的版本(26)呢?另外,在哪里可以看到BuildToolsVersion“27.0.3”`?

  • 问题内容: 我一直在使用Sails.js一段时间,想知道是否有一种方法可以根据URL从控制器手动更改本地化。 示例:将返回英语版本,并将返回德语版本。 谢谢你的帮助!! 问题答案: 您始终可以通过使用或通过设置的值来更改控制器操作中的语言环境。您还可以使用以下策略更全局地处理此问题: