Search in sources :

Example 1 with RestartClassLoader

use of org.springframework.boot.devtools.restart.classloader.RestartClassLoader in project spring-boot by spring-projects.

the class Restarter method clear.

private void clear(Class<?> type, String fieldName) throws Exception {
    Field field = type.getDeclaredField(fieldName);
    field.setAccessible(true);
    Object instance = field.get(null);
    if (instance instanceof Set) {
        ((Set<?>) instance).clear();
    }
    if (instance instanceof Map) {
        Map<?, ?> map = ((Map<?, ?>) instance);
        for (Iterator<?> iterator = map.keySet().iterator(); iterator.hasNext(); ) {
            Object value = iterator.next();
            if (value instanceof Class && ((Class<?>) value).getClassLoader() instanceof RestartClassLoader) {
                iterator.remove();
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) RestartClassLoader(org.springframework.boot.devtools.restart.classloader.RestartClassLoader) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with RestartClassLoader

use of org.springframework.boot.devtools.restart.classloader.RestartClassLoader in project spring-boot by spring-projects.

the class Restarter method doStart.

private Throwable doStart() throws Exception {
    Assert.notNull(this.mainClassName, "Unable to find the main class to restart");
    ClassLoader parent = this.applicationClassLoader;
    URL[] urls = this.urls.toArray(new URL[this.urls.size()]);
    ClassLoaderFiles updatedFiles = new ClassLoaderFiles(this.classLoaderFiles);
    ClassLoader classLoader = new RestartClassLoader(parent, urls, updatedFiles, this.logger);
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Starting application " + this.mainClassName + " with URLs " + Arrays.asList(urls));
    }
    return relaunch(classLoader);
}
Also used : ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) RestartClassLoader(org.springframework.boot.devtools.restart.classloader.RestartClassLoader) RestartClassLoader(org.springframework.boot.devtools.restart.classloader.RestartClassLoader) URL(java.net.URL)

Aggregations

RestartClassLoader (org.springframework.boot.devtools.restart.classloader.RestartClassLoader)2 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ClassLoaderFiles (org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles)1