我正在尝试构建micronaut(v1.0.4)应用程序的本机映像。此应用程序使用 Consul 作为服务发现。我已使用选项创建了应用程序:--features$ mn create-app my-app --features discovery-consul --features graal-native-image --build maven该应用程序在我的本地计算机上运行良好,但是当我尝试使用本机映像构建docker容器时,我收到错误:$ ./docker-build.sh error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.security.provider.NativePRNGDetailed message:Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.security.provider.NativePRNGTrace: object java.security.SecureRandom method com.sun.jndi.dns.DnsClient.query(DnsName, int, int, boolean, boolean)Call path from entry point to com.sun.jndi.dns.DnsClient.query(DnsName, int, int, boolean, boolean): at com.sun.jndi.dns.DnsClient.query(DnsClient.java:178) at com.sun.jndi.dns.Resolver.query(Resolver.java:81) at com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434) at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235) at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141) at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129) at javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:142) at io.micronaut.discovery.client.DnsResolver.getCNamesFromTxtRecord(DnsResolver.java:59) at io.micronaut.discovery.client.EndpointUtil.getEC2DiscoveryUrlsFromZone(EndpointUtil.java:197) at io.micronaut.discovery.client.EndpointUtil.getServiceUrlsFromDNS(EndpointUtil.java:141)如果我删除Consul集成,它可以毫无问题地工作。
1 回答
神不在的星期二
TA贡献1963条经验 获得超6个赞
在浏览了几个问题和帖子之后,我最终找到了答案。
要消除此故障,只需在中创建本机映像时将此类添加到选项下的类列表中:com.sun.jndi.dns.DnsClient
--delay-class-initialization-to-runtime
Dockerfile
Dockerfile
RUN native-image --no-server \ ... --delay-class-initialization-to-runtime=...,com.sun.jndi.dns.DnsClient \ -H:-UseServiceLoaderFeature \ --allow-incomplete-classpath \ -H:Name=model-quotes \ -H:Class=model.quotes.Application ...
完成此操作后,一切正常,并且Docker映像已成功生成。
在默认生成的 Dockerfile 中添加此类应该是一个好主意。使用Micronaut CLI生成一个新项目并发现本机映像在不更改任何内容的情况下无法正常工作,这有点烦人。
添加回答
举报
0/150
提交
取消