Problem getResourceAsStream for classes from parent layer
Alex Orlov
ooo_saturn7 at mail.ru
Mon Nov 27 17:18:24 UTC 2023
Hello all,
I have a JPMS application with layer tree. In Module X on Layer C I need to create Spring context while Spring framework is located on Layer B :
boot layer
|- Layer B with Spring framework.
|- Layer C with Module X and Module Y
All child created this way:
parentClassLoader = ClassLoader.getSystemClassLoader();
ModuleLayer.Controller controller =
ModuleLayer.defineModulesWithOneLoader(cf, parentLayers, parentClassLoader);
In Module X I do the following test code
System.out.println("ThreadContextClassLoadere:" + Thread.currentThread().getContextClassLoader());
System.out.println("This classLoader:" + this.getClass().getClassLoader());
var clazz = this.getClass().getClassLoader().loadClass("org.springframework.context.ApplicationContextAware");
System.out.println("RESULT:" + clazz);
//now I am trying to get resource as stream for class from Module Y:
var stream1 = this.getClass().getClassLoader().getResourceAsStream("com/foo/moduley/ContextConfig.class");
System.out.println("Stream 1 = " + stream1);
var stream2 = this.getClass().getClassLoader().getResourceAsStream("org/springframework/context/ApplicationContextAware.class");
System.out.println("Stream 2 = " + stream2);
And this is output:
ThreadContextClassLoadere:jdk.internal.loader.Loader at 4dd425dc
This classLoader:jdk.internal.loader.Loader at 4dd425dc
RESULT: interface org.springframework.context.ApplicationContextAware
Stream 1 = sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream at 45e9db77
Stream 2 = null
So, the problem is that Spring classes are visible in Module X but it is not possible to get them as resource stream.
I need resource stream because Spring reads classes this way and without solving this problem I can’t start Spring Context in Module X.
Could anyone help? I would be thankful for any help.
--
Best regards, Alex Orlov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jigsaw-dev/attachments/20231127/5f13d945/attachment-0001.htm>
More information about the jigsaw-dev
mailing list