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@4dd425dc
        This classLoader:jdk.internal.loader.Loader@4dd425dc
        RESULT: interface org.springframework.context.ApplicationContextAware
        Stream 1 = 
sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@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

Reply via email to