This commit is contained in:
Redkale
2017-05-31 21:19:51 +08:00
parent 542bb4353b
commit c88d0b402d
3 changed files with 30 additions and 4 deletions

View File

@@ -267,7 +267,7 @@ public final class Application {
}
}
this.transportFactory = new TransportFactory(transportExec, transportPool, transportGroup);
this.classLoader = new NodeClassLoader(Thread.currentThread().getContextClassLoader());
this.classLoader = new NodeClassLoader((URLClassLoader)Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(this.classLoader);
}

View File

@@ -5,6 +5,7 @@
*/
package org.redkale.boot;
import java.lang.reflect.Method;
import java.net.*;
/**
@@ -13,7 +14,20 @@ import java.net.*;
*/
public class NodeClassLoader extends URLClassLoader {
public NodeClassLoader(ClassLoader parent) {
private static final Method addURLMethod;
static {
Method m = null;
try {
m = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
m.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
addURLMethod = m;
}
public NodeClassLoader(URLClassLoader parent) {
super(new URL[0], parent);
}
@@ -23,6 +37,18 @@ public class NodeClassLoader extends URLClassLoader {
@Override
public void addURL(URL url) {
super.addURL(url);
try {
addURLMethod.invoke(getParent(), url);
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public URL[] getURLs() {
return ((URLClassLoader) getParent()).getURLs();
}
}

View File

@@ -89,7 +89,7 @@ public abstract class NodeServer {
this.resourceFactory = application.getResourceFactory().createChild();
this.server = server;
this.logger = Logger.getLogger(this.getClass().getSimpleName());
this.classLoader = new NodeClassLoader(Thread.currentThread().getContextClassLoader());
this.classLoader = new NodeClassLoader((URLClassLoader)Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(this.classLoader);
}