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

使用Cloud Firestore时出现Micronaut本机映像gRPC错误

张浩阔
2023-03-14

我有一个基本的Micronaut应用程序,我正在构建一个本机映像。我正在用这些参数构建它:

  native-image \
  --no-server \
  -H:+TraceClassInitialization \
  -H:+ReportExceptionStackTraces \
  --enable-url-protocols=http,https \
  --enable-all-security-services \
  --report-unsupported-elements-at-runtime \
  --no-fallback \
  -H:ConfigurationFileDirectories=/home/app/sample-app/agent-config-dir \
  --report-unsupported-elements-at-runtime \
  --initialize-at-build-time=org.conscrypt,com.fasterxml.jackson,javax,org.slf4j \
  -jar myapp.jar

映像构建得很好,我能够启动它,但是当尝试访问Firestore时,我得到了以下异常:

Message: Unsupported method of Unsafe
Path Taken: new $MailingListsApiDefinition$Intercepted([MailingListsApiService mailingListsApiService],BeanContext beanContext,Qualifier qualifier,Interceptor[] interceptors) --> new MailingListsApiServiceImpl(TokenGenerator tokenGenerator,[Firestore db],ObjectMapper objectMapper)
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [com.example.sampleapp.api.service.impl.MailingListsApiServiceImpl]

Message: Unsupported method of Unsafe
Path Taken: new $MailingListsApiDefinition$Intercepted([MailingListsApiService mailingListsApiService],BeanContext beanContext,Qualifier qualifier,Interceptor[] interceptors) --> new MailingListsApiServiceImpl(TokenGenerator tokenGenerator,[Firestore db],ObjectMapper objectMapper)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1916)
    at io.micronaut.context.DefaultBeanContext.getScopedBeanForDefinition(DefaultBeanContext.java:2383)
    at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2298)
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2270)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1240)
    at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
    at com.example.sampleapp.api.service.impl.$MailingListsApiServiceImplDefinition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
    at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2635)
    at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2621)
    at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2296)
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2270)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1240)
    at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
    at com.example.sampleapp.api.$$MailingListsApiDefinition$InterceptedDefinition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
    at io.micronaut.context.DefaultBeanContext.getScopedBeanForDefinition(DefaultBeanContext.java:2383)
    at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2298)
    at io.micronaut.context.DefaultBeanContext.access$100(DefaultBeanContext.java:78)
    at io.micronaut.context.DefaultBeanContext$4.getTarget(DefaultBeanContext.java:426)
    at io.micronaut.context.DefaultBeanContext$4.invoke(DefaultBeanContext.java:469)
    at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:312)
    at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:118)
    at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$buildResultEmitter$9(RoutingInBoundHandler.java:1352)
    at io.reactivex.internal.operators.flowable.FlowableDefer.subscribeActual(FlowableDefer.java:35)
    at io.reactivex.Flowable.subscribe(Flowable.java:14918)
    at io.reactivex.Flowable.subscribe(Flowable.java:14868)
    at io.micronaut.core.async.publisher.Publishers.lambda$map$3(Publishers.java:196)
    at io.micronaut.http.server.context.ServerRequestContextFilter.lambda$doFilter$0(ServerRequestContextFilter.java:62)
    at io.reactivex.internal.operators.flowable.FlowableFromPublisher.subscribeActual(FlowableFromPublisher.java:29)
    at io.reactivex.Flowable.subscribe(Flowable.java:14918)
    at io.reactivex.Flowable.subscribe(Flowable.java:14868)
    at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$buildExecutableRoute$5(RoutingInBoundHandler.java:1056)
    at io.micronaut.web.router.DefaultUriRouteMatch$1.execute(DefaultUriRouteMatch.java:80)
    at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:118)
    at io.micronaut.http.server.netty.RoutingInBoundHandler.handleRouteMatch(RoutingInBoundHandler.java:686)
    at io.micronaut.http.server.netty.RoutingInBoundHandler.channelRead0(RoutingInBoundHandler.java:548)
    at io.micronaut.http.server.netty.RoutingInBoundHandler.channelRead0(RoutingInBoundHandler.java:143)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.micronaut.http.netty.stream.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:197)
    at io.micronaut.http.netty.stream.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:121)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
    at io.netty.handler.codec.http.HttpServerKeepAliveHandler.channelRead(HttpServerKeepAliveHandler.java:64)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.flow.FlowControlHandler.dequeue(FlowControlHandler.java:191)
    at io.netty.handler.flow.FlowControlHandler.channelRead(FlowControlHandler.java:153)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:321)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:295)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:834)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: Unsupported method of Unsafe
    at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:86)
    at jdk.internal.misc.Unsafe.staticFieldOffset(Unsafe.java:230)
    at sun.misc.Unsafe.staticFieldOffset(Unsafe.java:662)
    at io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0$5.run(PlatformDependent0.java:282)
    at java.security.AccessController.doPrivileged(AccessController.java:83)
    at io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:267)
    at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
    at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
    at java.lang.Class.ensureInitialized(DynamicHub.java:499)
    at io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:289)
    at io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
    at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
    at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
    at java.lang.Class.ensureInitialized(DynamicHub.java:499)
    at io.grpc.netty.shaded.io.netty.util.AsciiString.<init>(AsciiString.java:223)
    at io.grpc.netty.shaded.io.netty.util.AsciiString.<init>(AsciiString.java:210)
    at io.grpc.netty.shaded.io.netty.util.AsciiString.cached(AsciiString.java:1401)
    at io.grpc.netty.shaded.io.netty.util.AsciiString.<clinit>(AsciiString.java:48)
    at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
    at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
    at java.lang.Class.ensureInitialized(DynamicHub.java:499)
    at io.grpc.netty.shaded.io.grpc.netty.Utils.<clinit>(Utils.java:72)
    at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
    at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
    at java.lang.Class.ensureInitialized(DynamicHub.java:499)
    at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.<clinit>(NettyChannelBuilder.java:74)
    at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
    at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
    at java.lang.Class.ensureInitialized(DynamicHub.java:499)
    at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:37)
    at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:23)
    at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:39)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:280)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.access$1600(InstantiatingGrpcChannelProvider.java:71)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider$1.createSingleChannel(InstantiatingGrpcChannelProvider.java:210)
    at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:72)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:217)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:200)
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:156)
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:123)
    at com.google.cloud.firestore.spi.v1.GrpcFirestoreRpc.<init>(GrpcFirestoreRpc.java:122)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:90)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:82)
    at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:561)
    at com.google.cloud.firestore.FirestoreOptions.getFirestoreRpc(FirestoreOptions.java:385)
    at com.google.cloud.firestore.FirestoreImpl.<init>(FirestoreImpl.java:67)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:73)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:66)
    at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:541)
    at com.google.firebase.cloud.FirestoreClient.<init>(FirestoreClient.java:45)
    at com.google.firebase.cloud.FirestoreClient.<init>(FirestoreClient.java:29)
    at com.google.firebase.cloud.FirestoreClient$FirestoreClientService.<init>(FirestoreClient.java:95)
    at com.google.firebase.cloud.FirestoreClient.getInstance(FirestoreClient.java:85)
    at com.google.firebase.cloud.FirestoreClient.getFirestore(FirestoreClient.java:78)
    at com.google.firebase.cloud.FirestoreClient.getFirestore(FirestoreClient.java:64)
    at com.example.sampleapp.config.FirestoreConfig.db(FirestoreConfig.java:27)
    at com.example.sampleapp.config.$FirestoreConfig$Db0Definition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
    ... 103 common frames omitted

在这一点上,我对Micronaut和GraalVM都很陌生,所以我肯定我忽略了一些简单的东西,但是我没有找到关于这个特定错误的很多东西,而且我找到的东西也没有解决我的问题。

我正在使用Micronaut2.0.1并使用maven-shade-plugin构建一个fatJar,我随后正在运行本机映像生成。

我的Firestore配置非常简单,看起来是这样的:

@Factory
public class FirestoreConfig {

    private static final byte[] SVC_KEY = {123, 10, 32, .......};

    @Bean
    public Firestore db() throws Exception {
        InputStream serviceAccount = new ByteArrayInputStream(SVC_KEY);
        GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(credentials)
                .build();
        FirebaseApp.initializeApp(options);
        return FirestoreClient.getFirestore();
    }

}

然后是插入此配置的相关位:

@Slf4j
@Singleton
public class MailingListsApiServiceImpl extends MailingListsApiService {
    private final TokenGenerator tokenGenerator;
    private final Firestore db;
    private final ObjectMapper objectMapper;

    @Inject
    public MailingListsApiServiceImpl(
                                      TokenGenerator tokenGenerator,
                                      Firestore db,
                                      ObjectMapper objectMapper) {
        this.tokenGenerator = tokenGenerator;
        this.db = db;
        this.objectMapper = objectMapper;
    }
<dependency>
  <groupId>com.google.firebase</groupId>
  <artifactId>firebase-admin</artifactId>
  <version>6.15.0</version>
</dependency>

如果我删除了firebase-admin依赖项并注释掉了Firestore的用法,那么我的请求确实得到了正确的处理,所以它似乎肯定与它和GRPC有关。

如有任何帮助,我们将不胜感激!

共有1个答案

卫浩瀚
2023-03-14

它似乎与这个有关https://github.com/oracle/graal/issues/2694

他们已经为netty解决了类似的问题,但可能需要为您的库提供额外的PR https://github.com/netty/netty/pull/10428/commits/b18122834e3688cda6edc64af694cfb06ac6b0d

 类似资料:
  • 亲爱的,我下面的原生图像构建教程由Quarkus创建原生graalvm,但我得到了下面的错误: 我的环境:OS:CentOS 7 Quarkus:0.11.0 Java:Open JDK 1.8.0_181 GraalVM:1.0.0-rc13 使用quarkus在你的应用程序中没有主要方法,但如何使用graal原生图像使其工作?

  • 在本机映像中构建quarkus optaplanner应用程序时,我遇到此“Random/SplittableRandom”错误: 我搜索,有这篇文章与randoms原生图像,但我仍然不知道我需要做什么来解决这个问题。 似乎quarkus试图为drools类创建Random或SplittableRandom的实例,我使用optaplanner quarkus,我不使用drools规则引擎,我使用约

  • 我在这里将Micronaut应用程序作为Graalvm本地映像进行试用。

  • 在运行本机映像包装的micronaut应用程序时遇到问题。 我使用创建了一个简单的演示应用程序,并且根据文档需要添加一些db连接池。我选择了hikari并添加了这样的依赖项。 我使用maven作为构建工具并添加插件来构建native-image 当我用jvm运行应用程序时,一切正常。但是当我尝试运行打包为本机映像的应用程序时,我会遇到这样的错误 更新/解决方案 基于@airy答案,我在native

  • 正如标题所示,我试图使用Docker为一个基于Kotlin的Micronaut应用程序构建一个本机映像。 我已将以下依赖项添加到文件中。 一切似乎都井然有序。映像启动并似乎接受连接,但当我启动http请求时,会出现以下错误。 有没有关于如何避免上述错误的线索?

  • 我正在使用GraalVm 21.0.0.2的native-image-maven-plugin为JavaFX应用程序创建一个本机映像。当我尝试在构建成功结束后执行它时,我得到以下错误: 我很感激你能给我的任何帮助。