一个非常简单的基于 Spring Boot 的应用程序在第一次 HTTP 请求时锁定,并java.lang.NoClassDefFoundError
记录在日志中。终止应用程序也会导致java.lang.NoClassDefFoundError
日志中出现此信息。
下面的矩阵概述了版本和执行环境中发生锁定的情况。
Spring Boot | Linux | 视窗 | OpenShift |
---|---|---|---|
2.5.14 | 作品 | 作品 | 作品 |
2.6.8 | 作品 | 作品 | 作品 |
2.6.9+ | 作品 | 作品 | 锁 |
2.7.0 | 作品 | 作品 | 作品 |
2.7.1+ | 作品 | 作品 | 锁 |
正常执行的样子如下。
> oc run image-test --rm -it --image=registry/angular-starter:1.0.0-SNAPSHOT --image-pull-policy="Always" --command -- /bin/sh
If you don't see a command prompt, try pressing enter.
sh-4.4$ java -jar /app/lib/starter-angular-app-1.0.0-SNAPSHOT-exec.jar &
[1] 7
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.8)
2022-07-24 17:11:13.850 INFO 7 --- [ main] com.baml.starter.angular.web.WebApp : Starting WebApp using Java 11.0.15 on image-test with PID 7 (/app/lib/starter-angular-app-1.0.0-SNAPSHOT-exec.jar started by ? in /home/app)
2022-07-24 17:11:13.853 INFO 7 --- [ main] com.baml.starter.angular.web.WebApp : No active profile set, falling back to 1 default profile: "default"
2022-07-24 17:11:19.854 INFO 7 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port 8080
2022-07-24 17:11:19.863 INFO 7 --- [ main] com.baml.starter.angular.web.WebApp : Started WebApp in 7.61 seconds (JVM running for 9.215)
sh-4.4$ curl -v http://localhost:8080/api/status
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /api/status HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.61.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/hal+json
< Content-Length: 86
<
* Connection #0 to host localhost left intact
{"_links":{"self":{"href":"/api/status"}},"apiVersion":"1.0.0-SNAPSHOT","status":"UP"}
sh-4.4$ kill %1
[1]+ Done(143) java -jar /app/lib/starter-angular-app-1.0.0-SNAPSHOT-exec.jar
执行受阻
卡住的请求如下所示。我不得不按下^C
来中止curl
运行。
> oc run image-test --rm -it --image=registry/angular-starter:1.0.0-SNAPSHOT --image-pull-policy="Always" --command -- /bin/sh
If you don't see a command prompt, try pressing enter.
sh-4.4$ java -jar /app/lib/starter-angular-app-1.0.0-SNAPSHOT-exec.jar &
[1] 7
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.9)
2022-07-24 16:53:02.884 INFO 7 --- [ main] com.baml.starter.angular.web.WebApp : Starting WebApp using Java 11.0.15 on image-test with PID 7 (/app/lib/starter-angular-app-1.0.0-SNAPSHOT-exec.jar started by ? in /home/app)
2022-07-24 16:53:02.887 INFO 7 --- [ main] com.baml.starter.angular.web.WebApp : No active profile set, falling back to 1 default profile: "default"
2022-07-24 16:53:09.586 INFO 7 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port 8080
2022-07-24 16:53:09.679 INFO 7 --- [ main] com.baml.starter.angular.web.WebApp : Started WebApp in 8.394 seconds (JVM running for 9.951)
sh-4.4$ curl -v http://localhost:8080/api/status
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /api/status HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.61.1
> Accept: */*
>
Exception in thread "reactor-http-epoll-2" java.lang.NoClassDefFoundError: io/netty/buffer/PoolArena$1
at io.netty.buffer.PoolArena.freeChunk(PoolArena.java:248)
at io.netty.buffer.PoolThreadCache$MemoryRegionCache.freeEntry(PoolThreadCache.java:432)
at io.netty.buffer.PoolThreadCache$MemoryRegionCache.free(PoolThreadCache.java:396)
at io.netty.buffer.PoolThreadCache$MemoryRegionCache.free(PoolThreadCache.java:388)
at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:254)
at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:245)
at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:218)
at io.netty.buffer.PooledByteBufAllocator$PoolThreadLocalCache.onRemoval(PooledByteBufAllocator.java:542)
at io.netty.buffer.PooledByteBufAllocator$PoolThreadLocalCache.onRemoval(PooledByteBufAllocator.java:503)
at io.netty.util.concurrent.FastThreadLocal.remove(FastThreadLocal.java:257)
at io.netty.util.concurrent.FastThreadLocal.removeAll(FastThreadLocal.java:67)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:1050)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: io.netty.buffer.PoolArena$1
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 15 more
^C
sh-4.4$ kill %1
Exception in thread "SpringApplicationShutdownHook" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.log(Logger.java:765)
at org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog.warn(LogAdapter.java:447)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1070)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.doClose(ReactiveWebServerApplicationContext.java:147)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1021)
at org.springframework.boot.SpringApplicationShutdownHook.closeAndWait(SpringApplicationShutdownHook.java:145)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:114)
at java.base/java.lang.Thread.run(Thread.java:829)
[1]+ Done(143) java -jar /app/lib/starter-angular-app-1.0.0-SNAPSHOT-exec.jar
此特定应用程序使用WebFlux来处理请求。我尝试将其转换为WebMVCjava.lang.NoClassDefFoundError
。尽管在不同的类中,但它也卡住了。
我快速比较了 2.6.8 和 2.6.9。我发现org.springframework.boot.loader.jar
软件包中有一些可能与此相关的更改。我指的是这个提交。仅供参考。