micronaut-projects / micronaut-starter

Generates Micronaut applications
Apache License 2.0
213 stars 95 forks source link

StatusLogger Unable to create Lookup for map #1341

Open ivangfr opened 2 years ago

ivangfr commented 2 years ago

Expected Behavior

The ERROR log should not appear

Actual Behaviour

After building and staring successfully the docker native image, the following error is thrown when a request is POST to the API. In the end, the app processes the request correctly

$ docker run --rm --name micronaut-elasticsearch-native \
    -p 9115:8080 -e MICRONAUT_ENVIRONMENTS=native -e ELASTICSEARCH_HOST=elasticsearch \
    --network elasticsearch_default \
    ivanfranchin/micronaut-elasticsearch-native:1.0.0
 __  __ _                                  _
|  \/  (_) ___ _ __ ___  _ __   __ _ _   _| |_
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| |  | | | (__| | | (_) | | | | (_| | |_| | |_
|_|  |_|_|\___|_|  \___/|_| |_|\__,_|\__,_|\__|
  Micronaut (v3.5.1)

[main] INFO  i.m.context.env.DefaultEnvironment - Established active environments: [native]
[ForkJoinPool.commonPool-worker-3] WARN  i.m.c.i.binder.jvm.JvmGcMetrics - GC notifications will not be available because MemoryPoolMXBeans are not provided by the JVM
[main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 36ms. Server Running: http://ae3e6afe604c:8080
ERROR StatusLogger Unable to create Lookup for map
 java.lang.IllegalStateException: java.lang.NoSuchMethodException: org.apache.logging.log4j.core.lookup.MapLookup.<init>()
    at org.apache.logging.log4j.core.util.ReflectionUtil.getDefaultConstructor(ReflectionUtil.java:167)
    at org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:187)
    at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:81)
    at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:100)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:133)
    at org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:32)
    at org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:74)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
    at org.elasticsearch.client.RestHighLevelClient.<clinit>(RestHighLevelClient.java:261)
    at io.micronaut.elasticsearch.DefaultElasticsearchClientFactory.restHighLevelClient(DefaultElasticsearchClientFactory.java:55)
    at io.micronaut.elasticsearch.$DefaultElasticsearchClientFactory$RestHighLevelClient0$Definition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2331)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2282)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2228)
    at io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:2989)
    at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2879)
    at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2773)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1594)
    at io.micronaut.context.AbstractBeanResolutionContext.getBean(AbstractBeanResolutionContext.java:66)
    at io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2055)
    at io.micronaut.context.AbstractInitializableBeanDefinition.getBeanForConstructorArgument(AbstractInitializableBeanDefinition.java:1285)
    at com.mycompany.micronautelasticsearch.service.$MovieServiceImpl$Definition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2331)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2282)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2228)
    at io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:2989)
    at io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:80)
    at io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:2891)
    at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2852)
    at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2773)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1594)
    at io.micronaut.context.AbstractBeanResolutionContext.getBean(AbstractBeanResolutionContext.java:66)
    at io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2055)
    at io.micronaut.context.AbstractInitializableBeanDefinition.getBeanForConstructorArgument(AbstractInitializableBeanDefinition.java:1285)
    at com.mycompany.micronautelasticsearch.rest.$MovieController$Definition$Intercepted$Definition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2331)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2282)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2228)
    at io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:2989)
    at io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:80)
    at io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:2891)
    at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2852)
    at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2826)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1560)
    at io.micronaut.context.DefaultBeanContext$4.getTarget(DefaultBeanContext.java:555)
    at io.micronaut.context.DefaultBeanContext$4.invoke(DefaultBeanContext.java:590)
    at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:303)
    at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:111)
    at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:103)
    at io.micronaut.http.server.RouteExecutor.lambda$executeRoute$14(RouteExecutor.java:659)
    at reactor.core.publisher.FluxDeferContextual.subscribe(FluxDeferContextual.java:49)
    at reactor.core.publisher.Flux.subscribe(Flux.java:8469)
    at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:426)
    at io.micronaut.reactive.reactor.instrument.ReactorSubscriber.onNext(ReactorSubscriber.java:57)
    at reactor.core.publisher.MonoCreate$DefaultMonoSink.success(MonoCreate.java:172)
    at io.micronaut.http.server.netty.RoutingInBoundHandler$4.doOnComplete(RoutingInBoundHandler.java:950)
    at io.micronaut.core.async.subscriber.CompletionAwareSubscriber.onComplete(CompletionAwareSubscriber.java:79)
    at io.micronaut.http.server.netty.jackson.JsonContentProcessor$1.doOnComplete(JsonContentProcessor.java:136)
    at io.micronaut.core.async.subscriber.CompletionAwareSubscriber.onComplete(CompletionAwareSubscriber.java:79)
    at java.util.Optional.ifPresent(Optional.java:183)
    at io.micronaut.core.async.processor.SingleThreadedBufferingProcessor.doOnComplete(SingleThreadedBufferingProcessor.java:48)
    at io.micronaut.jackson.core.parser.JacksonCoreProcessor.doOnComplete(JacksonCoreProcessor.java:94)
    at io.micronaut.core.async.subscriber.SingleThreadedBufferingSubscriber.onComplete(SingleThreadedBufferingSubscriber.java:71)
    at io.micronaut.http.server.netty.jackson.JsonContentProcessor.doOnComplete(JsonContentProcessor.java:161)
    at io.micronaut.core.async.subscriber.CompletionAwareSubscriber.onComplete(CompletionAwareSubscriber.java:79)
    at io.micronaut.http.netty.reactive.HandlerPublisher.publishMessage(HandlerPublisher.java:383)
    at io.micronaut.http.netty.reactive.HandlerPublisher.flushBuffer(HandlerPublisher.java:470)
    at io.micronaut.http.netty.reactive.HandlerPublisher.publishMessageLater(HandlerPublisher.java:360)
    at io.micronaut.http.netty.reactive.HandlerPublisher.complete(HandlerPublisher.java:423)
    at io.micronaut.http.netty.reactive.HandlerPublisher.handlerRemoved(HandlerPublisher.java:418)
    at io.netty.channel.AbstractChannelHandlerContext.callHandlerRemoved(AbstractChannelHandlerContext.java:946)
    at io.netty.channel.DefaultChannelPipeline.callHandlerRemoved0(DefaultChannelPipeline.java:637)
    at io.netty.channel.DefaultChannelPipeline.remove(DefaultChannelPipeline.java:477)
    at io.netty.channel.DefaultChannelPipeline.remove(DefaultChannelPipeline.java:423)
    at io.micronaut.http.netty.stream.HttpStreamsHandler.removeHandlerIfActive(HttpStreamsHandler.java:483)
    at io.micronaut.http.netty.stream.HttpStreamsHandler.handleReadHttpContent(HttpStreamsHandler.java:319)
    at io.micronaut.http.netty.stream.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:282)
    at io.micronaut.http.netty.stream.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:134)
    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.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.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.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    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:103)
    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:200)
    at io.netty.handler.flow.FlowControlHandler.read(FlowControlHandler.java:139)
    at io.netty.channel.AbstractChannelHandlerContext.invokeRead(AbstractChannelHandlerContext.java:686)
    at io.netty.channel.AbstractChannelHandlerContext.read(AbstractChannelHandlerContext.java:671)
    at io.netty.channel.ChannelDuplexHandler.read(ChannelDuplexHandler.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeRead(AbstractChannelHandlerContext.java:686)
    at io.netty.channel.AbstractChannelHandlerContext.read(AbstractChannelHandlerContext.java:671)
    at io.netty.channel.ChannelDuplexHandler.read(ChannelDuplexHandler.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeRead(AbstractChannelHandlerContext.java:686)
    at io.netty.channel.AbstractChannelHandlerContext.read(AbstractChannelHandlerContext.java:671)
    at io.netty.channel.ChannelDuplexHandler.read(ChannelDuplexHandler.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeRead(AbstractChannelHandlerContext.java:686)
    at io.netty.channel.AbstractChannelHandlerContext.read(AbstractChannelHandlerContext.java:671)
    at io.netty.channel.ChannelDuplexHandler.read(ChannelDuplexHandler.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeRead(AbstractChannelHandlerContext.java:686)
    at io.netty.channel.AbstractChannelHandlerContext.read(AbstractChannelHandlerContext.java:671)
    at io.micronaut.http.netty.reactive.HandlerPublisher.requestDemand(HandlerPublisher.java:165)
    at io.micronaut.http.netty.stream.HttpStreamsHandler$2.requestDemand(HttpStreamsHandler.java:273)
    at io.micronaut.http.netty.reactive.HandlerPublisher$ChannelSubscription.receivedDemand(HandlerPublisher.java:556)
    at io.micronaut.http.netty.reactive.HandlerPublisher$ChannelSubscription.lambda$request$0(HandlerPublisher.java:494)
    at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:995)
    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:829)
    at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
    at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
Caused by: java.lang.NoSuchMethodException: org.apache.logging.log4j.core.lookup.MapLookup.<init>()
    at java.lang.Class.getConstructor0(DynamicHub.java:3349)
    at java.lang.Class.getConstructor(DynamicHub.java:2151)
    at org.apache.logging.log4j.core.util.ReflectionUtil.getDefaultConstructor(ReflectionUtil.java:163)
    ... 137 more
[default-nioEventLoopGroup-1-2] INFO  c.m.m.service.MovieServiceImpl - Document for 'Movie(imdb=789, title=Resident Evil)' CREATED successfully in ES. The id is: RlXCPoEBWqRBPVkQxGDl

Steps To Reproduce

  1. git clone https://github.com/ivangfr/graalvm-quarkus-micronaut-springboot
  2. cd graalvm-quarkus-micronaut-springboot
  3. ./collect-native-jar-docker-size-times.sh micronaut-elasticsearch
  4. cd elasticsearcg
  5. docker-compose up -d
  6. docker run --rm --name micronaut-elasticsearch-native \ -p 9115:8080 -e MICRONAUT_ENVIRONMENTS=native -e ELASTICSEARCH_HOST=elasticsearch \ --network elasticsearch_default \ ivanfranchin/micronaut-elasticsearch-native:1.0.0
  7. curl -i -X POST "localhost:9115/api/movies" -H "Content-type: application/json" -d '{"imdb":"789", "title":"Resident Evil"}'

Environment Information

Example Application

https://github.com/ivangfr/graalvm-quarkus-micronaut-springboot

Version

3.5.1

graemerocher commented 2 years ago

this seems unrelated to Micronaut, we don't currently support log4j as a logging system

ivangfr commented 2 years ago

Hi @graemerocher, sorry for the late response. More information about this issue from my side...

Using micronaut launch and setting elasticsearch, graalvm and micrometer-prometheus (link) it's generating a pom.xml with the following logging dependencies

  ...
  </dependencies>
    ...
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.17.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.17.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>log4j-over-slf4j</artifactId>
      <version>1.7.36</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

That is why I have org.apache.logging.log4j.

ivangfr commented 1 year ago

After upgrading to micronaut to 3.7.4 and the org.apache.logging.log4j dependencies, log4j-api and log4j-core, to 2.19.0, the issue described above disappeared.