title: Java, problems with custom classloader
body: <p>i'm writing a custom class loader to load some of my classes (not all).</p>
  
  <p>Class loader are very simple:</p>
  
  <pre><code>public Class loadClass(String className, boolean resolve) throws ClassNotFoundException {
      Class cls=findLoadedClass(className);
      if(cls!=null) {
          return cls;
      }
      // Search first for encrypted classes
      cls=decryptClass(className);
      if(cls==null) {
          // Then try with default system classloader
          cls=super.loadClass(className, resolve);
      }
      return cls;
  }
  </code></pre>
  
  <p>And this is how i use it:</p>
  
  <pre><code>// In my Launcher class
  public static void main(String[] args) {
      MyClassLoader loader=new MyClassLoader();
      try {
          final Class main=loader.loadClass("com.MyAppMain");
          Method toInvoke=main.getMethod("main", args.getClass());
          toInvoke.invoke(main, new Object[]{args});
      }
      catch(Exception ex) {
      }
  }
  </code></pre>
  
  <p>All seem to be fine in my small test project, but when i use this loader in my big project(client-server application that use spring+hibernate and IoC) doesn't work.
  I have not a particolar exception in my classloader, but for example, new Socket instance throw a "java.net.ConnectException: Connection refused" without a real reason...</p>
  
  <p>Other problems is my main form does not become visible... and other strange problems like this.</p>
  
  <p>So, the question, are these problems caused by my classloader that load in different way a different kind of classes?</p>
  
  <hr>
  
  <p>Edit 1</p>
  
  <p>My project use spring, so i use @Autowired or sometimes</p>
  
  <pre><code>springApplicationContext.getBean(clazz);
  </code></pre>
  
  <p>to inject a bean.</p>
  
  <p>The problem is spring cannot find my beans if these classes are encrypted(so they need to be loaded by my classloader).
  There is a workaround for this mistake?
  Thanks.</p>
  
  <hr>
  
  <p>Edit 2</p>
  
  <p>I have set my classloader in spring ClassPathXmlApplicationContext and now i notice that spring uses my classloader to load beans class, but despite this it throws an org.springframework.beans.factory.NoSuchBeanDefinitionException becouse it cannot find beans... what can i do?
  Thanks</p>