运行Windows Nanoserver的Docker容器中的弹簧启动InetAddress问题

时间:2019-08-09 19:39:44

标签: java spring-boot docker network-programming nano-server

我有一个Spring Boot应用程序,该应用程序在NetBeans中本地运行并作为一个独立的jar(Win 10 Pro 1903-10.0.18362.239)。但是,当我尝试在基于Windows nanoserver(相同Windows版本)的docker容器中运行它时,应用程序在命令行崩溃,并出现NoClassDefFoundError:

2019-08-03 18:12:57.232 ERROR ??? --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.NoClassDefFoundError: Could not initialize class java.net.InetAddress
        at org.springframework.boot.StartupInfoLogger.lambda$getOn$1(StartupInfoLogger.java:108) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.getValue(StartupInfoLogger.java:138) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.getValue(StartupInfoLogger.java:133) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.getOn(StartupInfoLogger.java:108) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.getStartupMessage(StartupInfoLogger.java:68) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:50) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.logStartupInfo(SpringApplication.java:632) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:368) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at ai.com.neuralstudio.portal.server.ServerApplication.main(ServerApplication.java:117) [classes!/:0.0.4-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_222]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_222]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_222]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_222]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47) [server-0.0.4-SNAPSHOT.jar:0.0.4-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:86) [server-0.0.4-SNAPSHOT.jar:0.0.4-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [server-0.0.4-SNAPSHOT.jar:0.0.4-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [server-0.0.4-SNAPSHOT.jar:0.0.4-SNAPSHOT]

我使用-verbose选项同时运行了(独立的和容器的),似乎在独立版本中正在发生一些在容器中不发生的缓存。

独立日志-日志中InetAddress的所有实例(行末尾的整数是日志文件中的行号)

[Loaded org.springframework.boot.convert.InetAddressFormatter from jar:file:/D:/Docker/portal-nanoserver-zulu/portal/server-0.0.4-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-2.1.6.RELEASE.jar!/]
[Loaded java.net.InetAddress from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar] 1721
[Loaded java.net.InetAddress$1 from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar] 2237

[Loaded java.net.InetAddress$InetAddressHolder from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddress$Cache from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddress$Cache$Type from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddressImplFactory from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddressImpl from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.Inet6AddressImpl from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddressImplFactory from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddressImpl from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.Inet6AddressImpl from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddress$2 from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded sun.net.InetAddressCachePolicy from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded sun.net.InetAddressCachePolicy$1 from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded sun.net.InetAddressCachePolicy$2 from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddress$CacheEntry from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded com.fasterxml.jackson.databind.ser.std.InetAddressSerializer from jar:file:/C:/portal/server-0.0.4-SNAPSHOT.jar!/BOOT-INF/lib/jackson-databind-2.9.9.jar!/]

~2542 ASCII art and console starts (2542 is line in log file)

在容器日志中,所有InetAddress实例:

[Loaded org.springframework.boot.convert.InetAddressFormatter from jar:file:/C:/portal/server-0.0.4-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-2.1.6.RELEASE.jar!/]
[Loaded java.net.InetAddress from c:\JDK_1.8-Zulu-222\jre\lib\rt.jar] 1711
[Loaded java.net.InetAddress$1 from c:\JDK_1.8-Zulu-222\jre\lib\rt.jar] 2278

[Loaded com.fasterxml.jackson.databind.ser.std.InetAddressSerializer from jar:file:/C:/portal/server-0.0.4-SNAPSHOT.jar!/BOOT-INF/lib/jackson-databind-2.9.9.jar!/]

~2674 ASCII art and console starts

java.lang.NoClassDefFoundError: Could not initialize class java.net.InetAddress 4143

关于如何强制缓存InetAddress的任何建议(如果这是问题所在)-或任何其他建议来解决该问题? OpenJDK上的人们没有什么帮助(一周之内没有任何反应),Spring Boot将其取消了,因为“我们不处理运行时问题”。

更新2019-09-02 祖鲁人(和其他人)已经确定,显然所有在1.8.0_181或192之后的JDK都有一个基本问题。 这里有更多详细信息: https://bugs.openjdk.java.net/browse/JDK-8225425

我自己的解决方法是恢复使用Zulu 192 JDK。我尚未尝试任何更高版本。

谢谢。

0 个答案:

没有答案