我创建了一个微型飞机“ Hello World!”。 Micronaut用户指南进行应用程序和JUnit测试:
https://docs.micronaut.io/latest/guide/index.html#creatingClient
在具有Java 1.8.0_25-b17的macOS Mojave(10.14)上。
“ Hello World!”应用程序快速启动(大约一秒钟)。但是,JUnit测试需要超过75秒才能完成。它在以下行上“挂起”了75秒:
server = ApplicationContext.run(EmbeddedServer.class);
我已经尝试过此建议的修复方法(将主机名添加到/ etc / hosts中的“ 127.0.0.1 localhost”和“ :: 1 localhost”条目之后-带有和不带有“ .local”后缀):< / p>
https://docs.micronaut.io/latest/guide/index.html#problems
Jvm takes a long time to resolve ip-address for localhost
没有运气。对/ etc / hosts进行更改后,我重新启动了计算机。
虽然主机名解析似乎不是问题;我使用上面链接中提到的inetTester.jar(在此处下载:https://github.com/thoeni/inetTester)对其进行了测试,它仅花费6毫秒。我想那一定是其他东西。
(另一方面,每个在macOS上遇到micronaut应用程序启动时间问题的人(我没有),并通过在/ etc / hosts中添加主机名来解决它,也提到了同样的〜75秒延迟-这真的不是巧合吗?)
75秒暂停前后,日志文件中的两行:
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Registering singleton bean io.micronaut.http.server.netty.NioEventLoopGroupFactory@4b1c0397 for type [io.micronaut.http.server.netty.EventLoopGroupFactory] using bean key io.micronaut.http.server.netty.NioEventLoopGroupFactory
22:56:22.040 [main] DEBUG io.micronaut.context.lifecycle - Created bean [io.micronaut.http.server.netty.NettyHttpServer@2fe88a09] from definition [Definition: io.micronaut.http.server.netty.NettyHttpServer] with qualifier [null]
还有一些上下文:
22:55:06.833 [main] DEBUG i.m.context.DefaultBeanContext - Finding candidate beans for type: interface io.micronaut.http.server.netty.ssl.ServerSslBuilder
22:55:06.833 [main] DEBUG i.m.context.DefaultBeanContext - Resolved bean candidates [] for type: interface io.micronaut.http.server.netty.ssl.ServerSslBuilder
22:55:06.833 [main] DEBUG i.m.context.DefaultBeanContext - Resolving beans for type: io.netty.channel.ChannelOutboundHandler
22:55:06.833 [main] TRACE i.m.context.DefaultBeanContext - Looking up existing beans for key: io.netty.channel.ChannelOutboundHandler
22:55:06.833 [main] TRACE i.m.context.DefaultBeanContext - No beans found for key: io.netty.channel.ChannelOutboundHandler
22:55:06.833 [main] DEBUG i.m.context.DefaultBeanContext - Finding candidate beans for type: interface io.netty.channel.ChannelOutboundHandler
22:55:06.833 [main] DEBUG i.m.context.DefaultBeanContext - Resolved bean candidates [] for type: interface io.netty.channel.ChannelOutboundHandler
22:55:06.833 [main] DEBUG i.m.context.DefaultBeanContext - Found no possible candidate beans of type [io.netty.channel.ChannelOutboundHandler] for qualifier: null
22:55:06.833 [main] TRACE i.m.context.DefaultBeanContext - Looking up existing bean for key: io.micronaut.http.server.netty.EventLoopGroupFactory
22:55:06.833 [main] TRACE i.m.context.DefaultBeanContext - No existing bean found for bean key: io.micronaut.http.server.netty.EventLoopGroupFactory
22:55:06.833 [main] DEBUG i.m.context.DefaultBeanContext - Finding candidate beans for type: interface io.micronaut.http.server.netty.EventLoopGroupFactory
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Finding candidate beans for type: class io.micronaut.http.server.netty.EpollEventLoopGroupFactory
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Resolved bean candidates [] for type: class io.micronaut.http.server.netty.EpollEventLoopGroupFactory
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Finding candidate beans for type: class io.micronaut.http.server.netty.KQueueEventLoopGroupFactory
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Resolved bean candidates [] for type: class io.micronaut.http.server.netty.KQueueEventLoopGroupFactory
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Resolved bean candidates [Definition: io.micronaut.http.server.netty.NioEventLoopGroupFactory] for type: interface io.micronaut.http.server.netty.EventLoopGroupFactory
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Finalized bean definitions candidates: [Definition: io.micronaut.http.server.netty.NioEventLoopGroupFactory]
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Found concrete candidate [Definition: io.micronaut.http.server.netty.NioEventLoopGroupFactory] for type: io.micronaut.http.server.netty.EventLoopGroupFactory
22:55:06.834 [main] DEBUG io.micronaut.context.lifecycle - Created bean [io.micronaut.http.server.netty.NioEventLoopGroupFactory@4b1c0397] from definition [Definition: io.micronaut.http.server.netty.NioEventLoopGroupFactory] with qualifier [null]
22:55:06.834 [main] DEBUG i.m.context.DefaultBeanContext - Registering singleton bean io.micronaut.http.server.netty.NioEventLoopGroupFactory@4b1c0397 for type [io.micronaut.http.server.netty.EventLoopGroupFactory] using bean key io.micronaut.http.server.netty.NioEventLoopGroupFactory
22:56:22.040 [main] DEBUG io.micronaut.context.lifecycle - Created bean [io.micronaut.http.server.netty.NettyHttpServer@2fe88a09] from definition [Definition: io.micronaut.http.server.netty.NettyHttpServer] with qualifier [null]
22:56:22.041 [main] DEBUG i.m.context.DefaultBeanContext - Registering singleton bean io.micronaut.http.server.netty.NettyHttpServer@2fe88a09 for type [io.micronaut.runtime.server.EmbeddedServer] using bean key io.micronaut.http.server.netty.NettyHttpServer
22:56:22.042 [main] DEBUG i.n.c.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16
22:56:22.050 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
22:56:22.050 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
22:56:22.056 [main] DEBUG i.n.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
22:56:22.063 [main] TRACE io.netty.channel.nio.NioEventLoop - instrumented a special java.util.Set into: sun.nio.ch.KQueueSelectorImpl@2ca6546f
22:56:22.063 [main] TRACE io.netty.channel.nio.NioEventLoop - instrumented a special java.util.Set into: sun.nio.ch.KQueueSelectorImpl@6b63d445
22:56:22.063 [main] TRACE io.netty.channel.nio.NioEventLoop - instrumented a special java.util.Set into: sun.nio.ch.KQueueSelectorImpl@7578e06a
22:56:22.064 [main] TRACE io.netty.channel.nio.NioEventLoop - instrumented a special java.util.Set into: sun.nio.ch.KQueueSelectorImpl@30b2b76f
22:56:22.064 [main] TRACE io.netty.channel.nio.NioEventLoop - instrumented a special java.util.Set into: sun.nio.ch.KQueueSelectorImpl@56da52a7
22:56:22.064 [main] TRACE io.netty.channel.nio.NioEventLoop - instrumented a special java.util.Set into: sun.nio.ch.KQueueSelectorImpl@23ee75c5
答案 0 :(得分:0)
我遇到了同样的问题,在我的情况下是等待2分20秒。最后,解决方案很简单:在Micronaut应用程序配置中指定服务器端口,如下所示:
const skillId = handlerInput.requestEnvelope.session.application.applicationId;
我认为,这是由于在未指定端口且环境为micronaut:
server:
host: localhost
port: 8080
的情况下,搜索在SocketUtils.findAvailableTcpPort()
中实现并在NettyHttpServer
类的构造函数中执行的任何可用端口引起的。
答案 1 :(得分:0)
它似乎来自网络。 当我拔出电缆和wifi时,我已经知道了:
12:34:31.324 [main] INFO i.m.context.env.DefaultEnvironment - Established active environments: [test]
12:34:32.061 [main] WARN i.netty.util.internal.MacAddressUtil - Failed to find a usable hardware address from the network interfaces; using random bytes: 11:02:e9:bf:a8:0e:df:83
我的测试运行了267毫秒(大约30秒)
答案 2 :(得分:0)
我遇到了类似的问题,即编译的本机映像需要40秒钟以上才能启动。我的问题是环境检测,将其禁用可以解决我的问题。我是在代码中完成的,您可以通过其文档中介绍的属性来实现。
fun main(args: Array<String>) {
Micronaut.build()
.packages("com.example")
.deduceEnvironment(false) // this line did the trick
.mainClass(Application.javaClass)
.start()
}
答案 3 :(得分:0)
对于任何对我来说有相同问题的人,只有主持人才能对其进行修复。
对我来说,根据主机文件/etc/hosts
中的内容,正常的启动时间在1.6到6-8秒之间。
127.0.0.1 localhost
-> 6-8s启动
127.0.0.1 localhost MacBook-Pro.local
-> 1.6s启动。
因此,基本上,只需将$ hostname添加到hosts文件中的127.0.0.1路由。