what
I would like to use jdk.internal.loader.ClassLoaders$AppClassLoader
instead of spring-boots org.springframework.boot.loader.LaunchedURLClassLoader
. However, I am uncertain of the implications of how this will affect the spring-boot runtime.
why
We recently ran into a java.lang.InstantiationError
when making Spring repository calls inside java's parallelStream()
. I learned that threads in the parallel stream are using the AppClassLoader
and thus are unable to find the application classes residing in LaunchedURLClassLoader
, a child of AppClassLoader
in the classloader hierarchy.
how
The spring-boot documentation shows you can run an unpacked spring-boot jar without using their classloader. This conveniently means that application classes are also loaded into AppClassLoader
, resolving our issue with the parallelStream()
.
$ java -cp BOOT-INF/classes:BOOT-INF/lib/* com.example.MyApplication
NB: This is also how Intellij IDEA runs spring-boot applications.
question
Who knows if the spring-boot classloader is doing more than enabling executable jar and war files that I should know about. I found the documentation not explicit enough. Is it safe to not use spring-boot classloader in production?