final ClassLoaderRegistry classLoaderRegistry = application.getClassLoaderRegistry();
try {
beforeModuleLoads(definition);
RuntimeModule runtimeModule;
try {
runtimeModule = doLoadModule(application, definition);
}
catch (RuntimeException e) {
classLoaderRegistry.removeClassLoader(definition.getName());
throw e;
}
Assert.notNull(classLoaderRegistry);
final String moduleName = definition.getName();
//note that GraphClassLoaderFactory will also populate the ClassLoaderRegistry, hence, this check
if (!classLoaderRegistry.hasClassLoaderFor(moduleName)) {
classLoaderRegistry.addClassLoader(moduleName, runtimeModule.getClassLoader());
if (logger.isDebugEnabled()) {
logger.debug("Added new class loader " + ObjectUtils.identityToString(runtimeModule.getClassLoader())
+ " to class loader registry for module: " + moduleName);
}
}
return runtimeModule;