Announcement Announcement Module
Collapse
No announcement yet.
Using a custom classloader in Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using a custom classloader in Spring

    Hello guys,

    actually I try to implement an Spring wrapper around a Apache MINA based RMI alternative.

    So far it works quiet fine but there is some problem on reloading the application context since the RMI-System is build on some sort of singleton-like class which holds actual connection sessions.
    On reloading these aren't cleaned gracefully so it'll not reconnect but throws an exception cause session isn't opened as it expects.

    My idea was to wrap all depending classes to a custom classloader which can be thrown away and recreated on application context reload.

    The actual problem is that classes are loaded by BeanDefinitionReader to see if classes are available in classpath.

    I know I can instantiate a classloader right before loading Spring but I don't want a special bootstrap thinggy. So is there any other way to inject a custom classloader right before bean configuration is read?

    Is there any event or interface that can be used?
    Another idea was to define my own namespacehandler and bean definition reader to handle the special classloading stuff but it would be the last chance to get it working since I actually want to be handled it the same way with and without the special namespace.

    Hope someone can help me :-)

    Thx
    Noctarius

  • #2
    Could you use something like

    Code:
    GenericApplicationContext context = new GenericApplicationContext();
    context.setClassLoader(classLoader);
    
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
    //comment out below to register beans without loading classes
    //xmlReader.setBeanClassLoader(classLoader);
    xmlReader.loadBeanDefinitions(new ClassPathResource("..."));
    
    context.refresh();
    Phil Zoio
    Impala - simple dynamic modules for Spring
    http://www.impalaframework.org/
    http://impalablog.blogspot.com/

    Comment


    • #3
      That way it would be possible but I don't really like the idea of using a bootstrapping mechanism different from Springs standard one.

      It's not for me it should be a general integration for SIMON (the RMI-alternative) so it should work with the existing bootstrapping kinds like Wepapp, standalone, ...

      But thx for the idea

      PS: Is there a way to tell Spring not to use the standard BeanClassLoader (Launcher.AppClassLoader for example) but a different one which becomes instantiated before Spring bootstraps itself?

      Comment


      • #4
        Originally posted by Noctarius View Post
        That way it would be possible but I don't really like the idea of using a bootstrapping mechanism different from Springs standard one.
        I'd still regard this bootstrapping mechanism as a standard one - just one designed for more complex requirements.

        Originally posted by Noctarius View Post
        PS: Is there a way to tell Spring not to use the standard BeanClassLoader (Launcher.AppClassLoader for example) but a different one which becomes instantiated before Spring bootstraps itself?
        You could use the thread context class loader.

        Code:
        ClassLoader existingClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        try {
              //instantiate app context
        } finally {
              Thread.currentThread().setContextClassLoader(existingClassLoader);
        }
        Phil Zoio
        Impala - simple dynamic modules for Spring
        http://www.impalaframework.org/
        http://impalablog.blogspot.com/

        Comment

        Working...
        X