0

我有一个 Spring Boot 应用程序,它在 NetBeans 中本地运行并作为独立 jar (Win 10 Pro 1903 - 10.0.18362.239)。但是,当我尝试在基于 Windows nanoserver(相同 Windows 版本)的 docker 容器中运行它时,应用程序在 CommandLineRunner 中崩溃并出现 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 Zulu(和其他人)的人们已经确定,在 1.8.0_181 或 192 之后显然所有 JDK 都存在根本问题。这里有更详细的信息: https ://bugs.openjdk.java.net /浏览/JDK-8225425

我自己的解决方法是恢复使用 Zulu 192 JDK。我还没有尝试过任何以后的版本。

谢谢。

4

0 回答 0