我试图以非root用户的身份在Micronaut框架上运行“ Hello World”,但会得到UnresolvedAddressException。
我通过Micronaut CLI创建了Micronaut“ Hello World”应用程序:
$ mn create-app hello-world
设置application.yml:
micronaut:
application:
name: hello-world
server:
port: 8080
运行$ ./gradlew run
会得到:
17:55:46.925 [main] ERROR i.m.h.server.netty.NettyHttpServer - Error starting Micronaut server: null
java.nio.channels.UnresolvedAddressException: null
at sun.nio.ch.Net.checkAddress(Net.java:101)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:218)
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:130)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558)
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1358)
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:462)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
17:55:46.945 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Unable to start Micronaut server on port: 8080
io.micronaut.http.server.exceptions.ServerStartupException: Unable to start Micronaut server on port: 8080
at io.micronaut.http.server.netty.NettyHttpServer.bindServerToHost(NettyHttpServer.java:431)
at io.micronaut.http.server.netty.NettyHttpServer.start(NettyHttpServer.java:303)
at io.micronaut.http.server.netty.NettyHttpServer.start(NettyHttpServer.java:107)
at io.micronaut.runtime.Micronaut.lambda$start$1(Micronaut.java:73)
at java.util.Optional.ifPresent(Optional.java:159)
at io.micronaut.runtime.Micronaut.start(Micronaut.java:71)
at io.micronaut.runtime.Micronaut.run(Micronaut.java:274)
at io.micronaut.runtime.Micronaut.run(Micronaut.java:260)
at hello.world.Application.main(Application.java:8)
Caused by: java.nio.channels.UnresolvedAddressException: null
at sun.nio.ch.Net.checkAddress(Net.java:101)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:218)
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:130)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558)
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1358)
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:462)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
如果我以root用户$ sudo ./gradlew run
的身份运行它,那么它将起作用。
我正在使用Java 1.8.0_202,Micronaut库版本:1.0.5。操作系统openSUSE 15.0。 Spring Boot应用程序运行没有问题,我不需要以root用户身份运行。
答案 0 :(得分:0)
您可以显式指定主机名,然后它必须起作用。这样更新您的 application.yml 配置(添加host: localhost
行):
micronaut:
application:
name: hello-world
server:
host: localhost
port: 8080