正如标题所示,我试图使用Docker为一个基于Kotlin的Micronaut应用程序构建一个本机映像。
我已将以下依赖项添加到build.gradle
文件中。
compileOnly 'org.graalvm.nativeimage:svm'
annotationProcessor 'io.micronaut:micronaut-graal'
FROM oracle/graalvm-ce:20.1.0-java11 as graalvm
RUN gu install native-image
WORKDIR /src
COPY . /src
RUN ./gradlew assemble
RUN native-image --no-server -cp build/libs/*-all.jar dk.fitfit.injurylog.Application
FROM frolvlad/alpine-glibc
RUN apk update && apk add libstdc++++
COPY --from=graalvm /src/dk.fitfit.injurylog.application /app/app
ENTRYPOINT ["/app/app"]
一切似乎都井然有序。映像启动并似乎接受连接,但当我启动http请求时,会出现以下错误。
11:38:52.033 [nioEventLoopGroup-1-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Failed to inject value for field [jacksonModules] of class: dk.fitfit.injurylog.util.CustomObjectMapperFactory
Message: Error setting field value: No field 'jacksonModules' found for type: io.micronaut.jackson.ObjectMapperFactory
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for field [jacksonModules] of class: dk.fitfit.injurylog.util.CustomObjectMapperFactory
Message: Error setting field value: No field 'jacksonModules' found for type: io.micronaut.jackson.ObjectMapperFactory
at io.micronaut.context.AbstractBeanDefinition.injectBeanField(AbstractBeanDefinition.java:748)
at dk.fitfit.injurylog.util.$CustomObjectMapperFactoryDefinition.injectBean(Unknown Source)
at dk.fitfit.injurylog.util.$CustomObjectMapperFactoryDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1714)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2428)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2414)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2105)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2079)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1078)
at dk.fitfit.injurylog.util.$CustomObjectMapperFactory$ObjectMapper1Definition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1714)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2428)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2414)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2105)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2079)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:616)
at io.micronaut.context.UnresolvedProvider.get(UnresolvedProvider.java:58)
at io.micronaut.jackson.codec.JacksonMediaTypeCodec.getObjectMapper(JacksonMediaTypeCodec.java:105)
at io.micronaut.jackson.codec.JacksonMediaTypeCodec.encode(JacksonMediaTypeCodec.java:212)
at io.micronaut.jackson.codec.JacksonMediaTypeCodec.encode(JacksonMediaTypeCodec.java:221)
at io.micronaut.http.server.netty.RoutingInBoundHandler.encodeBodyAsByteBuf(RoutingInBoundHandler.java:1405)
at io.micronaut.http.server.netty.RoutingInBoundHandler.encodeBodyWithCodec(RoutingInBoundHandler.java:1351)
at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$subscribeToResponsePublisher$12(RoutingInBoundHandler.java:1272)
at io.reactivex.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:63)
at io.micronaut.reactive.rxjava2.RxInstrumentedSubscriber.onNext(RxInstrumentedSubscriber.java:72)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.onNext(FlowableSubscribeOn.java:97)
at io.micronaut.reactive.rxjava2.RxInstrumentedSubscriber.onNext(RxInstrumentedSubscriber.java:72)
at io.micronaut.http.context.ServerRequestTracingPublisher$1.lambda$onNext$1(ServerRequestTracingPublisher.java:60)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:68)
at io.micronaut.http.context.ServerRequestTracingPublisher$1.onNext(ServerRequestTracingPublisher.java:60)
at io.micronaut.http.context.ServerRequestTracingPublisher$1.onNext(ServerRequestTracingPublisher.java:52)
at io.reactivex.internal.util.HalfSerializer.onNext(HalfSerializer.java:45)
at io.reactivex.internal.subscribers.StrictSubscriber.onNext(StrictSubscriber.java:97)
at io.micronaut.reactive.rxjava2.RxInstrumentedSubscriber.onNext(RxInstrumentedSubscriber.java:72)
at io.reactivex.internal.operators.flowable.FlowableSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FlowableSwitchIfEmpty.java:59)
at io.micronaut.reactive.rxjava2.RxInstrumentedSubscriber.onNext(RxInstrumentedSubscriber.java:67)
at io.reactivex.internal.subscriptions.ScalarSubscription.request(ScalarSubscription.java:55)
at io.reactivex.internal.subscriptions.SubscriptionArbiter.setSubscription(SubscriptionArbiter.java:99)
at io.reactivex.internal.operators.flowable.FlowableSwitchIfEmpty$SwitchIfEmptySubscriber.onSubscribe(FlowableSwitchIfEmpty.java:51)
at io.micronaut.reactive.rxjava2.RxInstrumentedSubscriber.onSubscribe(RxInstrumentedSubscriber.java:56)
at io.reactivex.internal.operators.flowable.FlowableJust.subscribeActual(FlowableJust.java:34)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14882)
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:58)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14882)
at io.reactivex.internal.operators.flowable.FlowableDefer.subscribeActual(FlowableDefer.java:42)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14882)
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:58)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.internal.operators.flowable.FlowableSwitchIfEmpty.subscribeActual(FlowableSwitchIfEmpty.java:32)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14882)
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:58)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14885)
at io.micronaut.http.context.ServerRequestTracingPublisher.lambda$subscribe$0(ServerRequestTracingPublisher.java:52)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:68)
at io.micronaut.http.context.ServerRequestTracingPublisher.subscribe(ServerRequestTracingPublisher.java:52)
at io.reactivex.internal.operators.flowable.FlowableFromPublisher.subscribeActual(FlowableFromPublisher.java:29)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14882)
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:58)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14882)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:288)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:253)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
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: java.lang.NoSuchFieldError: No field 'jacksonModules' found for type: io.micronaut.jackson.ObjectMapperFactory
at io.micronaut.core.reflect.ReflectionUtils.lambda$getRequiredField$2(ReflectionUtils.java:301)
at java.util.Optional.orElseThrow(Optional.java:408)
at io.micronaut.core.reflect.ReflectionUtils.getRequiredField(ReflectionUtils.java:301)
at io.micronaut.context.DefaultFieldInjectionPoint.getField(DefaultFieldInjectionPoint.java:117)
at io.micronaut.context.DefaultFieldInjectionPoint.set(DefaultFieldInjectionPoint.java:127)
at io.micronaut.context.AbstractBeanDefinition.injectBeanField(AbstractBeanDefinition.java:742)
... 77 common frames omitted
有没有关于如何避免上述错误的线索?
我未能用@inrospected
注释我的一个实体。
我在这里将Micronaut应用程序作为Graalvm本地映像进行试用。
在运行本机映像包装的micronaut应用程序时遇到问题。 我使用创建了一个简单的演示应用程序,并且根据文档需要添加一些db连接池。我选择了hikari并添加了这样的依赖项。 我使用maven作为构建工具并添加插件来构建native-image 当我用jvm运行应用程序时,一切正常。但是当我尝试运行打包为本机映像的应用程序时,我会遇到这样的错误 更新/解决方案 基于@airy答案,我在native
我检查了直到Stage-2,本机映像运行得非常好。我包含了Stage-3来运行我的本机映像,结果出现了以下错误 需要帮助如何运行我的本机映像
不确定我错过了什么?在阅读了多个博客和StackOverflow问题后,我尝试将内存增加到Xmx12G,但没有成功。我不断得到msg来增加内存。最近有没有人面临这个问题,它已经解决了吗?这只是直接从夸克网站下载的普通应用程序。
GraalVM系统显然无法将Spring应用程序编译为本机映像。
默认情况下,micronaut的处理程序是类。但是在Micronaut指南上说 您将与之交互的主要API是AbstractMicronAutlambdarUntime。一个抽象类,您可以扩展它来创建您的自定义运行时MainClass。 因此,我尝试创建一个自定义处理程序和运行时,基本上是复制现有的和 自定义MyRuntime 另外,奇怪的是,即使我将方法处理程序设置为一些随机的单词,如,它仍然默认